SOAPMessage - SOAPConnection - gzip - how to

末鹿安然 提交于 2019-12-23 04:20:37

问题


I need to use compression when sending SOAP requests and receiving responses from the WebService. Unfortunately I didn't find any references on how to enable GZIP compression. Here is the simple code I use to send the soap request:

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

SOAPConnection sc = scf.createConnection();

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage message = mf.createMessage();

/*
.... some code
*/

URL url = new URL("https://blahblah/service/ws/Someservice");

SOAPMessage reply = sc.call(message, url);

Is there any way to enable the compression on the API level or will I have to wrap the SOAPMessage to implement compression myself?


回答1:


SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

SOAPConnection sc = scf.createConnection();

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage message = mf.createMessage();

//************** HERE YOU DO THE GZIP********************************

MimeHeaders hd = message .getMimeHeaders();
hd.addHeader("Accept-Encoding", "gzip,deflate,sdch");

/*
.... some code
*/

URL url = new URL("https://blahblah/service/ws/Someservice");

SOAPMessage reply = sc.call(message, url);


来源:https://stackoverflow.com/questions/4429320/soapmessage-soapconnection-gzip-how-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!