当前,我正在使用Java 11使用非常老的SOAP Web服务,其内容类型为: application / dime 。
我已经尝试过JAXWS,但是它不起作用,现在我正在发送一个普通的POST请求,并且能够接收到响应。
如我所见,响应由2个部分组成。第一个具有以</soap:Envelope>
结尾的xml,另一部分具有实际的PDF。
当我打开响应的内容时,删除第一行(这是XML)并保存带有.pdf扩展名的文件,那么我可以看到PDF了。
我正在尝试对HttpURLConnection做同样的事情,并且正在接收这样的字节数组:
byte[] encoded = Files.readAllBytes(Paths.get("C:\\Users\\aarzaluz\\request.xml"));
URL oURL = new URL("http://MMC0EIGDWebService/ServiceApp.asmx");
HttpURLConnection con = (HttpURLConnection) oURL.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "text/xml; charset=utf-8");
con.setRequestProperty("SOAPAction", "http://tempuri.org/MMWebService/ServiceApp/MM");
con.setDoOutput(true);
con.setDoInput(true);
// Then I send a request:
OutputStream reqStream = con.getOutputStream();
reqStream.write(encoded);
reqStream.flush();
reqStream.close();
// and pick up the response as follows:
InputStream resStream = con.getInputStream();
byte[] fileAsBytes = getArrayFromInputStream(resStream);
// TODO how to remove all the characters that come before: </soap:Envelope> pattern
writeContent(fileAsBytes, "C:\\Users\\aarzaluz\\response.pdf");
在响应中,如何删除</soap:Envelope>
之前的所有字符,然后保存在response.pdf中?