【问题标题】:No content in HttpResponse even though content is sent from server即使内容是从服务器发送的,HttpResponse 中也没有内容
【发布时间】:2014-12-23 21:31:58
【问题描述】:

代码:

HttpContent content = createLoginContent(username, password);
GenericUrl url = new GenericUrl(serverUrl);

HttpRequest postRequest = httpRequestFactory.buildPostRequest(url, content);
postRequest.setThrowExceptionOnExecuteError(false);
HttpResponse httpResponse = postRequest.execute();

对于状态码 OK (200),httpResponse.parseAsString() 返回我所期望的(从服务器发送的正文)。

但是,当我收到 401 状态代码时,httpResponse.parseAsString() 返回一个空字符串,即使服务器发送了一个“WRONG_USERNAME_OR_PASSWORD”正文。

当给出非 OK 状态代码时,我不能读取正文吗?如何使用 httpResponse 读取“WRONG_USERNAME_OR_PASSWORD”消息?

服务器已使用 RestClient-Tool 进行了测试,表明它确实在其响应中发送了正文。

【问题讨论】:

    标签: java google-http-client


    【解决方案1】:

    好的,我从使用 google-httpclient 更改为 apache-httpclient 并且效果更好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多