我使用ksoap2为Web服务方法调用。我用 ksoap2-机器人组装-2.5.4-JAR-与-dependencies.jar
,并能够从Web服务响应检索标头值。我想保存任何返回的cookie,并随后调用Web服务回报他们。
我用下面的code检索到的标题:
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);
相关推荐
最新文章