我需要在发送SOAP请求和从WebService接收响应时使用压缩。不幸的是,我没有找到任何关于如何启用GZIP压缩的参考。这是我用来发送soap请求的简单代码:
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);
有没有办法在API级别启用压缩,还是我必须自己包装SOAPMessage来实现压缩?
答案 0 :(得分: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);