问题描述
我正在用 java 发送一个 SoapMessage。我一直在设置正确的标题时遇到问题,确切地说是内容类型的部分,它应该是这样的:
Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="the boundary of my soapmessage"
我不知道如何将边界参数添加到我的标题中,以便它与soap 消息的其余部分相匹配。 我的肥皂消息看起来像这样:
------=_Part_0_5841104.1608651610791
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>
MYXML
------=_Part_0_5841104.1608651610791
Content-Type: application/zip; name=Worker.zip
Content-Transfer-Encoding: binary
Content-ID: <MYFILE.zip>
Content-Disposition: attachment; name="MYFILE.zip"; filename="MYFILEr.zip"
MYATTACHMENT
soapbody 中的边界部分是自动生成的(------=_Part_0_5841104.1608651610791),每次我发送消息时它都会改变。当我尝试添加标题时,我是这样做的:
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String authString = "login" + ":" + "password";
String enc = java.util.Base64.getEncoder().encodeToString((authString).getBytes(StandardCharsets.UTF_8));
MimeHeaders hd = soapMessage.getMimeHeaders();
hd.addHeader("POST","where");
hd.addHeader("Accept-Encoding","gzip,deflate");
hd.addHeader("Content-Type","multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"; boundary=\"----=_????????\"");
hd.addHeader("SOAPAction","Action");
hd.addHeader("MIME-Version","1.0");
hd.addHeader("Host","MyHost");
hd.addHeader("Connection","Keep-Alive");
hd.addHeader("User-Agent","Apache-HttpClient/4.1.1 (java 1.5)");
hd.addHeader("Authorization","Basic " + enc);
如何将这个适当的边界添加到我的标题中?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)