我正在尝试自动登录到一个网页。我在评估我是否通过了正确的证书。
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", "abc@xyz.com"));
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());发布于 2012-02-08 05:42:38
试一试
StatusLine l = response.getStatusLine();
System.out.println(l.getStatusCode() + " " + l .getReasonPhrase());输出?
发布于 2012-02-08 05:38:09
听起来你得到了一个授权请求重定向。这里可能已经介绍过了:Http Basic Authentication in Java using HttpClient?
发布于 2012-02-08 05:42:52
调查HttpResponse头,您可以找到内容类型和响应代码。这将帮助您找到问题所在。
https://stackoverflow.com/questions/9184229
复制相似问题