繁体   English   中英

即使内容是从服务器发送的,HttpResponse中也没有内容

[英]No content in HttpResponse even though content is sent from server

码:

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状态代码时,即使服务器发送了“ WRONG_USERNAME_OR_PASSWORD”正文,httpResponse.parseAsString()也会返回一个空字符串。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM