2011-06-17 71 views
6

我正在使用kso​​ap2进行Web服务方法调用。我使用ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar,并能够从Web服务响应中检索标题值。我想保存任何返回的cookie,并随后调用Web服务返回它们。如何保存并返回cookie到Web服务?

I retrieved the header using the following code:

SoapSerializationEnvelope信封=新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();  
    } 

我试图将其保存在SharedPreferences,但没有成功。我这样做有多冷?请帮忙。

在此先感谢。

+0

我出了错,当我试图读取SharedPreference的值,因此现在我能够拯救头内容。但是现在出现了一个新的异常:java.io.IOException:Content-Length下溢。怎么解决? – Ian 2011-06-17 07:02:35

回答

7

问题解决。

要保存报头内容:

  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(); 

设置cookie上请求:

HeaderProperty headerPropertyObj =新 HeaderProperty( “曲奇”, preferences.getString( “set-cookie”, “”));

headerList.add(headerPropertyObj);

androidHttpTransport.call(SOAP_ACTION, 信封,headerList);

相关问题