How to request a gzipped / compressed SOAP response?

狂风中的少年 提交于 2019-12-31 03:08:24

问题


i used the wsimport tool to create a soap client which is working very well. Now I like to request a compressed response from the server because the responses can be quite big.

I don't know if the server is able to send compressed content. As far as I know I have to add something like "Accept-Encoding: gzip" in the request.

How and where do I do that?

Thanks


回答1:


If your using ksoap jar for soap request then you need to set your compress method name on your header request. To set header your can use HeaderProperty class for that. Here is a simple example to send soap request.

    //Create Soap Object & their envelop
SoapObject soapObject=new SoapObject(NameSpace, methodName);
SoapSerializationEnvelope envelope=new  SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
//Add request params into object
soapObject.addProperty("paramsName", "paramsValue");
//set object into envelop
envelope.setOutputSoapObject(soapObject);
//Set header property which we like, here I dont want to set any compression method so I set "none". For ksoap default compression method is "gzip".
List<HeaderProperty> headers=new ArrayList<HeaderProperty>();
HeaderProperty headerProperty=new HeaderProperty("Accept-Encoding", "none");
headers.add(headerProperty);

//Create transport object.
HttpTransportSE httpTransportSE=new HttpTransportSE(url);
//call service
httpTransportSE.call(SOAP_ACTION, envelope,headers);
//recive response
JSONResponse=(String)envelope.getResponse();


来源:https://stackoverflow.com/questions/14624136/how-to-request-a-gzipped-compressed-soap-response

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