title: Sending and receiving HTTP post data - Java
body: <p>I'm trying to send a request through Google's Safe Browsing API, but I'm not getting any output and I'm not sure why. I've searched this online but each solution either only refers to only how to send or receive a POST request (but not both), or the input of data is done differently.</p>
  
  <p>According to the Google Safe Browsing documentation:</p>
  
  <blockquote>
    <p>Specify the queried URLs in the POST request body using the following format:</p>
    
    <p><code>POST_REQ_BODY = NUM LF URL (LF URL)*
    NUM = (DIGIT)+
    URL = URL string following the RFC 1738</code></p>
  </blockquote>
  
  <p>-</p>
  
  <blockquote>
    <p>Response body:</p>
    
    <p><code>POST_RESP_BODY = VERDICT (LF VERDICT)*
    VERDICT = “phishing” | “malware” | "unwanted" | “phishing,malware” &gt;| "phishing,unwanted" | "malware,unwanted" | "phishing, malware, unwanted" &gt;| “ok”</code></p>
  </blockquote>
  
  <p>and sent to:</p>
  
  <p><code>https://sb-ssl.google.com/safebrowsing/api/lookup?client=CLIENT&amp;key=APIKEY</code></p>
  
  <p>I found another topic that shows how you send this request, but I'm not sure how to get/print out the response. Here is what I tried:</p>
  
  <pre><code>String baseURL="https://sb-ssl.google.com/safebrowsing/api/lookup";
  String arguments = "";
  arguments +=URLEncoder.encode("client", "UTF-8") + "=" + URLEncoder.encode("myapp", "UTF-8") + "&amp;";
  arguments +=URLEncoder.encode("apikey", "UTF-8") + "=" + URLEncoder.encode("12345", "UTF-8") + "&amp;";
  arguments +=URLEncoder.encode("appver", "UTF-8") + "=" + URLEncoder.encode("1.5.2", "UTF-8") + "&amp;";
  arguments +=URLEncoder.encode("pver", "UTF-8") + "=" + URLEncoder.encode("3.0", "UTF-8");
  
  // Construct the url object representing cgi script
  URL url = new URL(baseURL + "?" + arguments);
  
  // Get a URLConnection object, to write to POST method
  URLConnection connect = url.openConnection();
  
  // Specify connection settings
  connect.setDoInput(true);
  connect.setDoOutput(true);
  
  InputStream input = connect.getInputStream();
  BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  StringBuilder result = new StringBuilder();
  String line;
  
  // Get an output stream for writing
  OutputStream output = connect.getOutputStream();
  PrintStream pout = new PrintStream (output);
  pout.print("2");
  pout.println();
  pout.print("http://www.google.com");
  pout.println();
  pout.print("http://www.facebook.com");
  pout.close();
  
  while((line = reader.readLine()) != null) {
     result.append(line);
  }
  System.out.println(result.toString());
  </code></pre>
  
  <p>Where is the error?</p>