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