有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Soap消息信封格式

我正在使用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 Supported ones are: [text/xml] com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/x-www-form-urlencoded Supported ones are: [text/xml]

可以的话,为了避免服务器错误,请您详细说明如何格式化邮件paylod

问候


共 (1) 个答案

  1. # 1 楼答案

    你有两个hardles

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

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

    如果你做了以上两个改变,它应该会起作用