title: Fail to Facebook api request using URLConnection in JAVA
body: <p>I am trying to developing Facebook API using Java.</p>
  
  <p>It is success to get access_token from facebook as flow.</p>
  
  <pre><code>        String access_token_url = targetURI +
                  "client_id=" + appId +
                  "&amp;client_secret=" + appSecret +
                  "&amp;code=" + code +
                  "&amp;redirect_uri=" + redirectURI; // 호출되지 않음
  
          URL url = new URL (access_token_url);
          URLConnection urlConn = url.openConnection();
          BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
          String accessTokenStr="";
  
          while ((accessTokenStr=in.readLine()) != null) {                
              int endPnt = accessTokenStr.indexOf("&amp;");
              access_token = accessTokenStr.substring(13, endPnt);
              System.out.println("@@@@@@@@@@@@@ access_token = " + access_token);
          }
          in.close();
  </code></pre>
  
  <p>This case(see the below source) occurred exception (code: 400) for get the own information using above access_token.</p>
  
  <pre><code>        String access_userInfo_url = "https://graph.facebook.com/me?" + "access_token=" + access_token;
  
          System.out.println("@@@@@@@@@@@ access_userInfo_url==============" + access_userInfo_url); 
  
          URL url = new URL (access_userInfo_url);
          HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
          BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
  
          urlConn.setRequestMethod("GET");
          //urlConn.setConnectTimeout(1000);
          //urlConn.setReadTimeout(1000);
          //urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          //urlConn.setRequestProperty("Content-Length", String.valueOf(access_userInfo_url.length()));              
  
          String userInfoStr="";          
          while ((userInfoStr=input.readLine()) != null) {
              System.out.println("@@@@@@@@@@@@@ userInfoStr = " + userInfoStr);   
          }
  
          input.close();
  </code></pre>
  
  <p>Recieved excetion message as flow.</p>
  
  <p>java.io.IOException: Server returned HTTP response code: 400 for URL: <a href="https://graph.facebook.com/me?access_token=CAAC7APV7WpoBAHVfr2ChZAK4wVrQZCjNSbro3LgABvoFSMMSHmiloS5m95z3DCeNsZBoOHFsClrgBVIqZCCwg8JZCK3Xd0fq6uyu8GJbYNENFQCDKz25IsguBSXuReapPvZA3ZC3BuJVLPwpZAfVCZCqFW0wj6o6ZA6nXO5JzCutZBAum2cJQjiBwctFkzxWqxinz8ZD" rel="nofollow">https://graph.facebook.com/me?access_token=CAAC7APV7WpoBAHVfr2ChZAK4wVrQZCjNSbro3LgABvoFSMMSHmiloS5m95z3DCeNsZBoOHFsClrgBVIqZCCwg8JZCK3Xd0fq6uyu8GJbYNENFQCDKz25IsguBSXuReapPvZA3ZC3BuJVLPwpZAfVCZCqFW0wj6o6ZA6nXO5JzCutZBAum2cJQjiBwctFkzxWqxinz8ZD</a>
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
      at biztopia.facebook.web.FacebookController.requestUserInfo(FacebookController.java:318)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)</p>
  
  <p>~
  ~
  ~
  ~</p>
  
  <p>I'm confused that it is success when request on web-browser(explorer) as "<a href="https://graph.facebook.com/me?access_token=Token" rel="nofollow">https://graph.facebook.com/me?access_token=Token</a> value".</p>
  
  <p>Please help me who have solutions.</p>