2017-06-19 2 views
0

Ich möchte eine Authentifizierungsanfrage an Google senden. Aber ich bekomme den Fehler: Ausnahme im Thread "Haupt" java.io.IOException: Server zurückgegeben HTTP-Antwortcode: 400 für URL.Senden Sie eine Authentifizierungsanfrage an Google

Kann mir jemand helfen und sagen, wo der Fehler liegt?

Mein Code sieht wie folgt aus:

public class Main 
{ 
    public static void main(String... args) throws Exception 
    {  
     String httpsURL ="\n" + 
       " client_id=xxx.apps.googleusercontent.com&\n" + 
       " response_type=code&\n" + // "code" is an Basic Value 
       " scope=openid%20email&\n" + 
       " redirect_uri=http://localhost&\n" + 
       " state=security_token%3D138r5719ru3e1%26url%3Dhttps://oauth2-login-demo.example.com/myHome&\n" + 
       " [email protected]\n"; 
     String inputLine; 

     String httpsencode ="https://accounts.google.com/o/oauth2/v2/auth?" + URLEncoder.encode(httpsURL, "UTF-8"); 

     URL u = new URL(httpsencode);   
     HttpsURLConnection con = (HttpsURLConnection)u.openConnection(); 
     InputStream ins = con.getInputStream(); 
     InputStreamReader isr = new InputStreamReader(ins); 
     BufferedReader in = new BufferedReader(isr); 

     while ((inputLine = in.readLine()) != null) 
     { 
      System.out.println(inputLine); 
     } 
     in.close();    
    } 
} 

Antwort

Verwandte Themen