C# 当客户端是windows/控制台应用程序时,webservice如何维护会话?
当客户端是windows/Console应用程序时,webservice如何维护会话?使用cookieC# 当客户端是windows/控制台应用程序时,webservice如何维护会话?,c#,web-services,C#,Web Services,当客户端是windows/Console应用程序时,webservice如何维护会话?使用cookie 发送HTTP请求时,请确保包含CookieContainer。(假设您使用的是HttpWebRequest)在封面下,C#WebClient正在存储web服务提供给它的cookie。如果有人感兴趣,这里有一些示例代码 class Program { static void Main(string[] args) { CookieContainer session
发送HTTP请求时,请确保包含
CookieContainer
。(假设您使用的是HttpWebRequest
)在封面下,C#WebClient正在存储web服务提供给它的cookie。如果有人感兴趣,这里有一些示例代码
class Program
{
static void Main(string[] args)
{
CookieContainer session = new CookieContainer();
HttpWebRequest httpSomeRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someURL");
httpSomeRequest.CookieContainer = session;
httpSomeRequest.GetResponse();
HttpWebRequest httpSomeOtherRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someOtherURL");
httpSomeOtherRequest.CookieContainer = session;
httpSomeOtherRequest.GetResponse();
}
}
我们只需要确保每个
HttpWebRequest
都使用相同的CookieContainer
实例。你能给我一些如何使用CookiContainer的例子吗?@santosh:request.CookieContainer=someContainer
someContainer
应该是所有请求共享的CookieContainer
实例。你有使用CookieContainer的例子吗?@santosh:你有什么问题吗?你看过文档了吗?谢谢你的快速回复。我要试一试。