簡體   English   中英

httpclient響應

[英]httpclient response

我正在嘗試自動登錄到網頁。 我假設我通過了正確的憑據。

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());

嘗試

  StatusLine l = response.getStatusLine();
  System.out.println(l.getStatusCode() + "  " + l .getReasonPhrase());

輸出?

聽起來您正在獲得授權請求重定向。 這可能已經在這里涵蓋: 使用HttpClient的Java中的Http基本身份驗證?

研究HttpResponse標頭,可以找到內容類型和響應代碼。 這將幫助您發現問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM