How to save and return cookies to the web service?

前端 未结 1 1110
旧巷少年郎
旧巷少年郎 2020-12-09 13:45

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 w

1条回答
  •  醉梦人生
    2020-12-09 14:33

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

    0 讨论(0)
提交回复
热议问题