3

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

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

我如何以及在哪里这样做?

谢谢

4

1 回答 1

2

如果您使用 ksoap jar 进行肥皂请求,那么您需要在标头请求中设置压缩方法名称。要设置标题,您可以使用 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();
于 2013-03-01T05:51:34.513 回答