http客户端响应
我正在尝试自动登录网页。我假设我通过了正确的凭据。
entity.getContentLength() 显示 20 但我看到的响应格式不正确。它不是 HTML。我应该如何进一步进行。下面是我的代码。
String input_text = "https://www.abc.com";
HttpPost httpost = new HttpPost(input_text);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("email", "[email protected]"));
nvps.add(new BasicNameValuePair("passsword", "ttyyeri"));
nvps.add(new BasicNameValuePair("publicLoginToken",""));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
entity = response.getEntity();
if (entity != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String readLine;
while(((readLine = br.readLine()) != null)) {
System.err.println("br :"+readLine);
}
System.out.println("Response content length: " + entity.getContentLength());
}
System.out.println("HTML Content :::"+entity.getContent().toString());
I am trying to autologin into a webpage. Im asssuming that i pass the proper credentials.
entity.getContentLength() shows 20 but the repsonse i see is not well formatted. It is not an HTML. How should i proceed further. Below is my code.
String input_text = "https://www.abc.com";
HttpPost httpost = new HttpPost(input_text);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("email", "[email protected]"));
nvps.add(new BasicNameValuePair("passsword", "ttyyeri"));
nvps.add(new BasicNameValuePair("publicLoginToken",""));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
entity = response.getEntity();
if (entity != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String readLine;
while(((readLine = br.readLine()) != null)) {
System.err.println("br :"+readLine);
}
System.out.println("Response content length: " + entity.getContentLength());
}
System.out.println("HTML Content :::"+entity.getContent().toString());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
输出?
try
output ?
听起来您正在收到授权请求重定向。这可能已经在这里介绍过:Java 中使用 HttpClient 进行 Http Basic 身份验证?
Sounds like you are getting an authorization request redirect. This may have already been covered here: Http Basic Authentication in Java using HttpClient?
研究 HttpResponse 标头,您可以找到内容类型和响应代码。
这将帮助您找到问题。
Investigate the HttpResponse Header, you can find the content type and the response code.
Which will help you to find the problem.