Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpResponse中没有内容,即使内容是从服务器发送的_Java_Google Http Client - Fatal编程技术网

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

Java HttpResponse中没有内容,即使内容是从服务器发送的,java,google-http-client,Java,Google Http Client,代码: 对于状态代码OK 200,httpResponse.parseAsString返回我期望从服务器发送的内容 然而,当我得到401状态码时,httpResponse.parseAsString返回一个空字符串,即使服务器发送了一个“错误的用户名”或“密码”正文 当给出非正常状态代码时,我是否可以不读取正文?如何使用httpResponse读取“错误的\u用户名\u或\u密码”消息 服务器已经使用RestClient工具进行了测试,以表明它确实在响应中发送了一个主体。好的,我从使用googl

代码:

对于状态代码OK 200,httpResponse.parseAsString返回我期望从服务器发送的内容

然而,当我得到401状态码时,httpResponse.parseAsString返回一个空字符串,即使服务器发送了一个“错误的用户名”或“密码”正文

当给出非正常状态代码时,我是否可以不读取正文?如何使用httpResponse读取“错误的\u用户名\u或\u密码”消息


服务器已经使用RestClient工具进行了测试,以表明它确实在响应中发送了一个主体。

好的,我从使用google httpclient改为使用apache httpclient,它工作得更好

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

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