Java 向Google发送身份验证请求
我想向谷歌发送一个身份验证请求。 但是我得到了错误:线程“main”java.io.IOException中的异常:服务器返回了HTTP响应代码:400作为URL。 有人能帮我说说错误在哪里吗 我的代码如下所示:Java 向Google发送身份验证请求,java,https,google-oauth,Java,Https,Google Oauth,我想向谷歌发送一个身份验证请求。 但是我得到了错误:线程“main”java.io.IOException中的异常:服务器返回了HTTP响应代码:400作为URL。 有人能帮我说说错误在哪里吗 我的代码如下所示: public class Main { public static void main( String... args ) throws Exception { String httpsURL ="\n" + "
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" +
" login_hint=peterpan@googlemail.com\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();
}
}
尝试删除httpsURL中的所有“\n”。
在两个GET参数之间不需要换行字符
编辑:http错误代码400解释如下: