Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当客户端是windows/控制台应用程序时,webservice如何维护会话?_C#_Web Services - Fatal编程技术网

C# 当客户端是windows/控制台应用程序时,webservice如何维护会话?

C# 当客户端是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

当客户端是windows/Console应用程序时,webservice如何维护会话?

使用cookie


发送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:你有什么问题吗?你看过文档了吗?谢谢你的快速回复。我要试一试。