title: Java HTTP get request to facebook. Bad request
body: <p>I wrote some code to interact with facebook from the client side using a browser control which worked.</p>
  
  <p>I'm trying to run a servlet app for authentication with facebook. The servlet reuses a class I used in the client.</p>
  
  <p>The value of url_conn is: 
  <a href="https://graph.facebook.com/oauth/access_token?client_id=" rel="nofollow">https://graph.facebook.com/oauth/access_token?client_id=</a>{my-id string}&amp;client_secret={alphanumeric string secret}&amp;fb_exchange_token={Really long alphanumeric string}&amp;grant_type=fb_exchange_token 
  . I've removed the actual values where {} are used.</p>
  
  <p>Here's the code. What is wrong? Please provide some guidance. Thanks</p>
  
  <pre><code> try{
          System.out.println("Attempting to open connection");
      conn = (HttpURLConnection) (url_conn.openConnection());
        if (conn.getResponseCode() != 200) {
              System.out.println("Throwing IO Exception Successful on " + url_conn.toString());
          throw new IOException(conn.getResponseMessage());
        }
      //  conn.setRequestProperty("Accept-Charset","UTF-8");
        System.out.println("Attempt Successful");
  
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
        String json = reader.readLine();
        JsonReader MyJsonReader = Json.createReader(reader);
        JsonObject jsonObject = MyJsonReader.readObject();
  
        MyJsonReader.close();
        reader.close();        
  
        sb = sb.append(jsonObject.toString());    
       }
  catch(Exception e)
  {
      System.out.println("Error From The FileCounter Class " + e.getMessage());
      e.printStackTrace();
  
  }
  
    conn.disconnect();      
      }  
  </code></pre>