向Google发送身份验证请求(Send an authentication request to Google)

编程入门 行业动态 更新时间:2024-10-21 13:40:32
向Google发送身份验证请求(Send an authentication request to Google)

我想向Google发送身份验证请求。 但我收到错误: 线程“main”中的异常java.io.IOException:服务器返回HTTP响应代码:400为URL。

有人可以帮助我并说出错误所在吗?

我的代码如下:

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(); } }

I would like a Send an authentication request to Google. But I get the error: Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL.

Can someone help me and say where the error lies?

My code looks as follows:

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”。 您不需要2 GET参数之间的新行char。

编辑:http错误代码400解释如下:http: //www.checkupdown.com/status/E400.html

Try to remove all yours "\n" in httpsURL. You don't need new line char between 2 GET arguments.

Edit : http error code 400 explained here : http://www.checkupdown.com/status/E400.html

更多推荐

本文发布于:2023-04-28 00:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Google   Send   request   authentication

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!