GetMessages 是我在 .net 网络服务中为我的聊天程序提供的一种方法。它获取消息集合,仅通过将最后一个消息 ID 保存在会话变量中来发送新消息。
HeaderProperty mSessionHeader = null;
public SoapObject GetMessages()
{
...
SoapObject request = new SoapObject(NAMESPACE, METHOD);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.V11);
envelope.dotNet = true;
envelope.bodyOut = request;
HttpTransport transport = new HttpTransport(URL);
transport.debug = true;
// Build request header
LinkedList<HeaderProperties> reqHeaders = new LinkList<HeaderProperties>();
if (mSessionHeader != null) {
reqHeaders.add(mSessionHeader); //using the session id from last header
}
List<HeaderProperties> respHeaders = transport.call(ACTION, envelope, reqHeaders);
// See note after code
for (HeaderProperty hp : respHeaders) {
if (hp.getKey().equalsIgnoreCase("set-cookie"))
{
mSessionHeader = hp;
break;
}
}
return (SoapObject) envelope.getResponse();
}
mSessionHeader 的值类似于
设置cookie:ASP.NET_SessionId=0zzfwxxp1sakeafybjzsxp0k;路径=/; HttpOnly
但是,GUID 部分将每次调用都更改为
...无论我在 Web 服务中设置的位置如何
我是否必须添加更多标头,然后只添加 ASP.NET_SessionId?