首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >httpclient响应

httpclient响应
EN

Stack Overflow用户
提问于 2012-02-08 05:26:56
回答 3查看 2.1K关注 0票数 1

我正在尝试自动登录到一个网页。我在评估我是否通过了正确的证书。

entity.getContentLength()显示20,但我看到的响应声格式不好。它不是HTML。我应该如何继续下去。下面是我的代码。

代码语言:javascript
复制
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());
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-02-08 05:42:38

试一试

代码语言:javascript
复制
  StatusLine l = response.getStatusLine();
  System.out.println(l.getStatusCode() + "  " + l .getReasonPhrase());

输出?

票数 1
EN

Stack Overflow用户

发布于 2012-02-08 05:38:09

听起来你得到了一个授权请求重定向。这里可能已经介绍过了:Http Basic Authentication in Java using HttpClient?

票数 0
EN

Stack Overflow用户

发布于 2012-02-08 05:42:52

调查HttpResponse头,您可以找到内容类型和响应代码。这将帮助您找到问题所在。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9184229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档