How to request a gzipped / compressed SOAP respons

2019-02-25 18:46发布

问题:

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();