如何保存并返回饼干到Web服务? [英] How to save and return cookies to the web service?
问题描述
我使用ksoap2为Web服务方法调用。我用 ksoap2-机器人组装-2.5.4-JAR-与-dependencies.jar
,并能够从Web服务响应检索标头值。我想保存任何返回的cookie,并随后调用Web服务回报他们。
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(要求); HttpTransportSE androidHttpTransport =新HttpTransportSE(URL); 名单headerList = androidHttpTransport.call(SOAP_ACTION,信封,NULL); 对于(对象标题:headerList){ HeaderProperty headerProperty =(HeaderProperty)头; 串headerKey = headerProperty.getKey(); 串headerValue = headerProperty.getValue(); }
我试图将其保存在共享preferences,但没有成功。我有多冷做到这一点?请帮忙。
在此先感谢。
问题解决了。
要保存包头的内容:
编辑共享preferenceEditor = preferences.edit(); 名单headerList = androidHttpTransport.call(SOAP_ACTION,信封,NULL); 对于(对象标题:headerList){ HeaderProperty headerProperty =(HeaderProperty)头; 串headerKey = headerProperty.getKey(); 串headerValue = headerProperty.getValue(); 的System.out.println(headerKey +:+ headerValue); 共享preferenceEditor.putString(headerKey,headerValue); } 共享preferenceEditor.commit();
要根据要求设置cookie:
HeaderProperty headerPropertyObj =新 HeaderProperty(曲奇, preferences.getString(设置Cookie, ));
headerList.add(headerPropertyObj);
androidHttpTransport.call(SOAP_ACTION, 信封,headerList);
I'm using ksoap2 for web service method calls. I used ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar
and was able to retrieve header values from the web service response. I would like to save any returned cookies and return them with subsequent calls to the web service.
I retrieved the header using the following code:
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); List headerList = androidHttpTransport.call(SOAP_ACTION, envelope, null); for (Object header : headerList) { HeaderProperty headerProperty = (HeaderProperty) header; String headerKey = headerProperty.getKey(); String headerValue = headerProperty.getValue(); }
I tried to save it in SharedPreferences, but was unsuccessful. How cold I do this? Please help.
Thanks in advance.
Issue solved.
To save the header contents:
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();
To set the cookie on request:
HeaderProperty headerPropertyObj = new HeaderProperty("cookie", preferences.getString("set-cookie", ""));
headerList.add(headerPropertyObj);
androidHttpTransport.call(SOAP_ACTION, envelope, headerList);
这篇关于如何保存并返回饼干到Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!