我正在尝试使用Java登录到https://flow.polar.com/login页面。我用“ email”和“ password”值进行了发布请求。我应该重定向到页面以授权从用户那里获取数据,但是要安装200响应并重定向到主页(https://flow.polar.com)。正常登录时,我正在检查浏览器请求选项中的所有值,但仍然出现此错误。 我的问题是,是否有什么我需要登录的信息,或者是否有单击登录按钮的方法?
我还要补充一点,当我提供错误的电子邮件或密码时得到400响应。因此,除了即时通讯重定向到错误的页面外,其他一切似乎都可以正常工作:(
这是我的代码:
URL obj = new URL(url);
HttpsURLConnection conn1 = (HttpsURLConnection) obj.openConnection();
// Acts like a browser
conn1.setUseCaches(false); // just going to main page instead of logging!!!
conn1.setRequestMethod("POST");
conn1.setRequestProperty("Host", "flow.polar.com");
conn1.setRequestProperty("User-Agent", USER_AGENT);
conn1.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn1.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
conn1.setRequestProperty("Accept-Language", "pl,en-US;q=0.7,en;q=0.3");
conn1.setRequestProperty("Connection", "keep-alive");
conn1.setRequestProperty("Referer", "https://flow.polar.com/login?n=D6FQQAAAAAAAAAAACXDM2CSAIAIABYDX3GB5XJTBP5IPEIESYYNNTUUOLAD6JXLR7H5G4EKE2WFJJ4MIOOLP54XGF6GJ4Q5T2G7HFWFJR7TUVNPDSEJLO6AKWH3WG3IIFTRKIJCZKVEAKMCJDSUPYZSUV2WYMDFU5CPBOIZJBGZGCAAAAA%3D%3D%3D%3D%3D%3D");
conn1.setDoOutput(true);
conn1.setDoInput(true);
// Send post request
DataOutputStream wr = new DataOutputStream(conn1.getOutputStream());
wr.writeBytes(postParams);
System.out.println(postParams);
wr.flush();
wr.close();
int responseCode = conn1.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + postParams);
System.out.println("Response Code : " + responseCode);
BufferedReader in =
new BufferedReader(new InputStreamReader(conn1.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
System.out.println("Response: ");
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
答案 0 :(得分:0)
Okey。我知道了问题是我没有发布所有输入文件。我忘记了隐藏的东西。 这是工作代码:
Connection.Response response1 =
Jsoup.connect("https://flow.polar.com/login?n=XXX")
.userAgent(USER_AGENT)
.timeout(10 * 1000)
.method(Method.POST)
.data("email", "xxx@gmail.com")
.data("password", "passwd")
.data("returnUrl", "/?n=XXX")
.followRedirects(true)
.execute();