【发布时间】:2021-04-06 01:30:39
【问题描述】:
我在 java 中发送一个 SoapMessage。我一直在设置正确的标头时遇到问题,正是 Content-Type 的一部分,应该如下所示:
Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="the boundary of my soapmessage"
我不知道如何将边界参数添加到我的标题中,以便它与肥皂消息的其余部分相匹配。 我的肥皂信息如下所示:
------=_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);
如何将这个适当的边界添加到我的标题中?
【问题讨论】: