Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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 http apache客户端未接收内容_Java_Http_Apache Httpclient 4.x - Fatal编程技术网

java http apache客户端未接收内容

java http apache客户端未接收内容,java,http,apache-httpclient-4.x,Java,Http,Apache Httpclient 4.x,我正在使用Apache client libs for http client将一些数据发布到我的服务器 下面是代码,我得到了状态行响应,但我没有得到内容。 但在wireshark上,我可以看到服务器响应的内容很少,例如内容类型、位置等。对于我的代码,我得到以下输出 Status :: HTTP/1.1 201 Created Content null 请帮我找出我在阅读内容时出错的地方,我需要一些与代理相关的设置吗 HttpClient client = new DefaultHttpCli

我正在使用Apache client libs for http client将一些数据发布到我的服务器

下面是代码,我得到了状态行响应,但我没有得到内容。 但在wireshark上,我可以看到服务器响应的内容很少,例如内容类型、位置等。对于我的代码,我得到以下输出

Status :: HTTP/1.1 201 Created Content null
请帮我找出我在阅读内容时出错的地方,我需要一些与代理相关的设置吗

HttpClient client = new DefaultHttpClient();
String line = "";      String status = "";
HttpPost post = new HttpPost("http://127.0.0.1/msg");
try {

  HttpEntity e = new StringEntity("POSTING TO SERVER FOR TESTING");
  post.setEntity(e);


  HttpResponse response = client.execute(post);
  BufferedReader rd = new BufferedReader(new
  InputStreamReader(response.getEntity().getContent()));
  status = response.getStatusLine().toString() ;
  while ((line = rd.readLine()) != null) {
    System.out.println(line);
  }

} catch (IOException e) {
  e.printStackTrace();
}

System.out.println(" Status :: "+ status + " Content " + line);

Status::HTTP/1.1 201创建内容null
的原因是,分配给
line
的最后一个值是
null
(这是您如何打破循环的)。响应可能没有任何内容。您可以根据需要使用API检查标头


请看一个例子

Status::HTTP/1.1 201创建内容null的原因是因为分配给
的最后一个值是
null
。响应可能没有任何内容。您可以根据需要使用API检查标题在“Status:”行之前打印了什么?这就是你的内容。我怀疑这只是你的观察不好,不是一个真正的问题。