添加用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);