使用Ksoap2从android中的webservice获取响应头

时间:2012-10-11 05:47:04

标签: java android android-ksoap2

我的web服务在.net中,我已经在android中使用KSOAP2成功从Soap Response获取数据。我想从头部获取响应头和一些细节,任何人都可以帮助如何使用KSOAP2获取响应头?

1 个答案:

答案 0 :(得分:1)

>   The HttpTransportSE class exposes the method call that, beyond the
> required SOAP    parameters, also accepts a List of HeaderProperty
> instances. It also returns a like List. This provides the ability to
> append additional headers to the request and review the returned
> headers. Since a cookie is just one of those header, one can use this
> facility to send and receive cookies.

The response headers are returned by the "call" method. So you just need to keep track of your JSESSIONID and pass it back again for each call. I overlooked this small detail at first as well. ;)

Keep in mind that the server returns the JSESSIONID with a "set-cookie" header, but it needs to be sent with a "cookie" header.

List respHeaders = android_http.call(SOAP_ACTION, envelope2, reqHeaders); 
for(int ix=0; ix<respHeaders.size(); ix++) { 
        HeaderProperty hp = (HeaderProperty)respHeaders.get(ix); 
        System.out.println("Header"+ix+"="+hp.getKey()+" / "+hp.getValue()); 
}