本帖最后由 sknice 于 2012-08-16 16:57:43 编辑

解决方案 »

  1.   

    http://topic.csdn.net/u/20110627/16/92379162-470a-49b7-aa9a-700b0cf0545c.html
    这个帖子讨论过,但是没有说解决办法。
      

  2.   

     HttpGet httpGet = new HttpGet();括号里应该有网址的,你把url放进去试试吧。
      

  3.   

    String url="http://192.168.1.83/imonitorint.html?op=r&33032=0";
    这个url在浏览器中直接打开是有返回结果的,但是在代码中执行就会出错
      

  4.   

    发帖的时候拷贝错了,项目的代码是有参数的 public static String getResultByHttpGet()
    throws ClientProtocolException, IOException
    {
    String result = "";
    url="http://192.168.1.83/imonitorint.html?op=r&33032=0";
    HttpGet httpGet = new HttpGet(url);
    HttpResponse response = new DefaultHttpClient().execute(httpGet);
    if (response.getStatusLine().getStatusCode() == 200)
    {
    HttpEntity entity = response.getEntity();
    result = EntityUtils.toString(entity, "GB2312");
    }
    return result;
    }
      

  5.   

    HttpGet httpGet = new HttpGet(url);
      

  6.   


    DefaultHttpClient client = new DefaultHttpClient()
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); 
    HttpResponse response = client.execute(httpGet);
    试试看?
      

  7.   


    服务器那端是你们自己写的吗?
    能debug下那里看看,httpclient过来和浏览器过来有什么不一样吗?
      

  8.   

    还有浏览器也许容错性比httpclient好。
    你们那个url是输出xml? 下载文件?
    请检查服务器端contentType 和header内容等。
      

  9.   


    你装个httpwatch,一个ie的插件。
    可以看服务器端返回的response的全部内容。
    比如httpheader。猜猜看那里比较奇怪造成 httpclient解析header失败了。(DefaultResponseParser.parseHead)
      

  10.   

    89       @Override
       90       protected HttpMessage parseHead(
       91               final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
       92           //read out the HTTP status string
       93           int count = 0;
       94           ParserCursor cursor = null;
       95           do {
       96               // clear the buffer
       97               this.lineBuf.clear();
       98               int i = sessionBuffer.readLine(this.lineBuf);
       99               if (i == -1 && count == 0) {
      100                   // The server just dropped connection on us
      101                   throw new NoHttpResponseException("The target server failed to respond");
      102               }
      103               cursor = new ParserCursor(0, this.lineBuf.length());
      104               if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) {
      105                   // Got one
      106                   break;
      107               } else if (i == -1 || count >= this.maxGarbageLines) {
      108                   // Giving up
      109                   throw new ProtocolException("The server failed to respond with a " +
      110                           "valid HTTP response");
      111               }
      112               if (this.log.isDebugEnabled()) {
      113                this.log.debug("Garbage in response: " + this.lineBuf.toString());
      114               }
      115               count++;
      116           } while(true);
      117           //create the status line from the status string
      118           StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
      119           return this.responseFactory.newHttpResponse(statusline, null);
      120       }看109行~~
      

  11.   

    返回的head为空。浏览器怎么可以解析
      

  12.   

    你上面贴得不是response的header吧?
      

  13.   


    我看你第一张图的时候发的贴
    果然没有收到的header。
    我觉得是服务器端程序有问题的吧。应该你们这里改得话,你只能去改httpclient的库吧。
    或者有什么设置可以让httpclient不要去做parseHead
      

  14.   

    不知道应该怎么设置httpClient,使其接受格式错误的响应头部信息。
    这里有片文章介绍,但是介绍的不够详细。
    http://www.cnblogs.com/loveyakamoz/archive/2011/07/21/2113251.html
      

  15.   

    不要在普通J2SE应用中调用,放到Web开发的Servlet程序里应该就可以了。