【问题标题】:Soap message envelope formatting肥皂消息信封格式
【发布时间】:2018-06-29 08:38:10
【问题描述】:

我正在使用 JAva HttpsURLConnection 发送 Soap 信封消息。请参阅下面我的肥皂信封有效负载:

OutputStream out = con.getOutputStream();
      Writer wout = new OutputStreamWriter(out);

      wout.write("<?xml version='1.0' encoding='UTF-8'?>\r\n");  
      wout.write("<S:Envelope xmlns:S= ");
      wout.write(
        "'http://schemas.xmlsoap.org/soap/envelope/'>\r\n"
      );
      wout.write("<S:Body><ns2:getAccessibleDBs xmlns:ns2=");
      wout.write(
        "'http://webservice.namespace.com/'>\r\n"); 
      wout.write("  </ns2:getAccessibleDBs>\r\n");
       wout.write("  </S:Body>\r\n"); 
      wout.write("</S:Envelope>\r\n"); 

      wout.flush();
      wout.close();

但是服务器消息如下:

com.sun.xml.ws.transport.http.HttpAdapter E Unsupported Content-Type: application/x-www-form-urlencoded 支持的有:[text/xml] com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/x-www-form-urlencoded 支持的是: [text/xml]

可以,请您提供有关如何格式化消息paylod以避免服务器错误的见解。

问候,

【问题讨论】:

标签: java soap soapexception


【解决方案1】:

你有两个困难,

  1. 您没有设置服务器所期望的准确 HTTP 标头 Content-Type="text/xml"
  2. 您的 XML 不正确。它应该如下所示,没有不必要的换行符 \r\n 等,命名空间应该以 double quote 开头,而不是单引号。

    &lt;xml version="1.0" encoding="UTF-8"?&gt; &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;S:Body&gt;&lt;ns2:getAccessibleDBs xmlns:ns2="http://webservice.namespace.com/"&gt; &lt;/ns2:getAccessibleDBs&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;

如果你做了以上两个更改,它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多