gpt4 book ai didi

android - 如何保存 cookie 并将其返回给网络服务?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:52:22 26 4
gpt4 key购买 nike

我正在使用 ksoap2 进行网络服务方法调用。我使用了 ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar 并且能够从 Web 服务响应中检索 header 值。我想保存任何返回的 cookie,并在随后调用 Web 服务时返回它们。

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

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

提前致谢。

最佳答案

问题已解决。

保存标题内容:

          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 = new HeaderProperty("cookie", preferences.getString("set-cookie", ""));

headerList.add(headerPropertyObj);

androidHttpTransport.call(SOAP_ACTION, envelope, headerList);

关于android - 如何保存 cookie 并将其返回给网络服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6381491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com