【发布时间】:2013-10-28 09:45:32
【问题描述】:
在https://accounts.google.com/o/oauth2/token 请求令牌时浪费了大量时间在谷歌上搜索“错误请求”的可能原因后,我决定问为什么这段代码只能获得“错误请求”响应服务器...
String url = "https://accounts.google.com/o/oauth2/token";
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setChunkedStreamingMode(0);
con.setRequestMethod("POST");
con.setRequestProperty("Host", "accounts.google.com");
con.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
con.setRequestProperty("code", authCode);
con.setRequestProperty("client_id",
"[CLIENT_ID]");
con.setRequestProperty("client_secret", "[CLIENT_SECRET");
con.setRequestProperty("redirect_uri",
"http://localhost:8080/login");
con.setRequestProperty("grant_type", "authorization_code");
// Send post request
con.setDoOutput(true);
我确实必须设置con.setChunkedStreamingMode(0),因为服务器返回了与内容长度相关的错误。
有什么想法吗? 是否有必要将有效载荷放在一行中?如何?
【问题讨论】:
标签: java oauth oauth-2.0 httpsurlconnection