如何请求压缩/压缩的SOAP响应?

时间:2013-01-31 11:00:52

标签: soap compression gzip

我使用wsimport工具创建了一个运行良好的soap客户端。 现在我想从服务器请求压缩响应,因为响应可能非常大。

我不知道服务器是否能够发送压缩内容。据我所知,我必须在请求中添加类似“Accept-Encoding:gzip”的内容。

我该怎样以及在哪里这样做?

由于

1 个答案:

答案 0 :(得分:1)

如果您使用kso​​ap jar for soap请求,则需要在标头请求中设置压缩方法名称。要设置标题,您可以使用HeaderProperty类。这是一个发送soap请求的简单示例。

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