Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 HttpURLConnection始终返回错误500_Java_Http - Fatal编程技术网

Java HttpURLConnection始终返回错误500

Java HttpURLConnection始终返回错误500,java,http,Java,Http,我试图在一个基本的http请求中运行一个soap请求……当然,我尝试了使用外部工具来传递消息,并且是正确的,就像我使用的作为targetUrl的端点一样,wsdl是 http://00.00.00.00/a-ws/services/basic?wsdl 我的实际终点是 http://00.00.00.00/a-ws/services/basic.targetservice 我使用最后一个作为目标url URL url = new URL(targetUrl);

我试图在一个基本的http请求中运行一个soap请求……当然,我尝试了使用外部工具来传递消息,并且是正确的,就像我使用的作为targetUrl的端点一样,wsdl是

http://00.00.00.00/a-ws/services/basic?wsdl
我的实际终点是

http://00.00.00.00/a-ws/services/basic.targetservice
我使用最后一个作为目标url

          URL url = new URL(targetUrl);
          connection = (HttpURLConnection)url.openConnection();
          connection.setRequestMethod("POST");
          connection.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
          connection.setRequestProperty("SOAPAction", action);
          connection.setRequestProperty("User-Agent", "myagent");
          connection.setRequestProperty("Host", "localhost");
          //connection.setRequestProperty("Content-Length", "" + Integer.toString(message.getBytes().length));

          connection.setUseCaches (false);
          connection.setDoInput(true);
          connection.setDoOutput(true);

          //Send request
          OutputStream wr = connection.getOutputStream ();
          wr.write (message.getBytes());
          wr.flush ();
          wr.close ();

          //Get Response    
          InputStream is = connection.getInputStream();
          BufferedReader rd = new BufferedReader(new InputStreamReader(is));
          String line=null;
          StringBuffer response = new StringBuffer(); 
          while( (line = rd.readLine()) != null) {
              if (line!=null)
                  response.append(line);
          }
          rd.close();
          return response.toString();
原始消息是用chrome插件测试的,我唯一不能测试的是标题,但结果总是在getInputStream上出现异常

java.io.IOException: Server returned HTTP response code: 500 for URL:

为什么?

这是一个非常愚蠢的编码问题(就像我猜想的那样)…我没有逃脱消息中的双引号

问题的证据是使用一个只回显内容的假http服务器可见的

更新: 另一件没有人指出的事情是,在检索异常的情况下,这是有用的

connection.getErrorStream()


包含错误情况下的响应

错误500是服务器的响应,您应该调查他为什么向您发送此消息。可能它没有收到它所期望的(数据?),如果我尝试从浏览器插件中发送相同的消息,那么我已经告诉过。这是一个客户端问题,服务器只是说由于一般原因无法处理请求,可能是编码,但我不知道在何处以及如何执行SOAP命令,试着使用一个框架——例如,用这种方式来处理原始SOAP将依赖于大量样板代码。我们无法确定服务器为什么会出错。也许您需要包含Accepts头?这只是一个建议-如果您可以选择使用定制包,如Apache或Spring for HttpURLClient-使用它们。这是避免依赖关系的明确决定,而且axis看起来也不太可靠!我怎样才能得到更多的细节?