android php cookies,android联接webservice是cookies和session保持方法

android连接webservice是cookies和session保持方法

添加用android连接 php的 nusoap 做成的webservice是session和cookies不能保存,经过查找在国外的一个网站上找到了解决方法,具体实现方法如下(http://www.my400800.cn

):

取得请求页面cookies内容,等下次发送请求时在把cookies的内容发送过去

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.dotNet = true;  SharedPreferences preferences =null;

HttpTransportSE  androidHttpTransport  = new HttpTransportSE(URL);

Editor sharedPreferenceEditor = preferences.edit();

List headerList = androidHttpTransport.call(SOAP_ACTION, envelope, null);

for (Object header : headerList) {

HeaderProperty headerProperty = (HeaderProperty) header;

String headerKey = headerProperty.getKey();

String headerValue = headerProperty.getValue();

System.out.println(headerKey +" : " + headerValue);

sharedPreferenceEditor.putString(headerKey, headerValue);

}

sharedPreferenceEditor.commit();

把取得请求页面cookies内容在发送给下一个请求的页面,就实现了cookies内容的保持,代码如下:

HeaderProperty headerPropertyObj = new HeaderProperty("cookie", preferences.getString("set-cookie", ""));

headerList.add(headerPropertyObj);

androidHttpTransport.call(SOAP_ACTION, envelope, headerList);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值