2014-10-28 75 views
0

代码发送:中的HttpResponse没有内容,即使内容从服务器

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进行了测试,表明它确实在响应中发送了一个主体。

回答

0

好的,我从使用谷歌的httpclient更改为apache-httpclient,它工作得更好。