Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.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# Restsharp响应中缺少Cookie_C#_Restsharp - Fatal编程技术网

C# Restsharp响应中缺少Cookie

C# Restsharp响应中缺少Cookie,c#,restsharp,C#,Restsharp,我将Restsharp用于我正在开发的WPF客户端 似乎我在client.CookieContainer中没有收到任何cookie,在我成功向服务器进行身份验证后,它始终有0个项目 这很奇怪,因为相同的请求是通过Postman发送的,而我收到的JSESSIONID cookie在使用Restsharp发送请求时不存在 public static async Task<IRestResponse> SendLogonRequest(string UID, SecureString pw

我将Restsharp用于我正在开发的WPF客户端

似乎我在client.CookieContainer中没有收到任何cookie,在我成功向服务器进行身份验证后,它始终有0个项目

这很奇怪,因为相同的请求是通过Postman发送的,而我收到的JSESSIONID cookie在使用Restsharp发送请求时不存在

public static async Task<IRestResponse> SendLogonRequest(string UID, SecureString pwd)
    {
        var restClient = new RestClient(new Uri(URLSRV))
        {
            Authenticator = new HttpBasicAuthenticator(UID, pwd.ToInsecureString())                //base64 auth;
        };
        restClient.CookieContainer = new CookieContainer();
        var restRequest = new RestRequest(Method.POST);
        restRequest.AddHeader("Accept", "application/json");
        restRequest.AddHeader("Content-Type", "application/json");

        var cancellationTokenSource = new CancellationTokenSource();
        var restResponse = await restClient.ExecuteTaskAsync(restRequest, cancellationTokenSource.Token);

        return restResponse;
    }
公共静态异步任务SendLogonRequest(字符串UID,SecureString pwd)
{
var restClient=new restClient(新Uri(URLSRV))
{
Authenticator=new-HttpBasicAuthenticator(UID,pwd.ToInsecureString())//base64 auth;
};
restClient.CookieContainer=新CookieContainer();
var restRequest=新的restRequest(Method.POST);
AddHeader(“接受”、“应用程序/json”);
AddHeader(“内容类型”、“应用程序/json”);
var cancellationTokenSource=新的cancellationTokenSource();
var restreponse=wait restClient.ExecuteTaskAsync(restRequest,cancellationTokenSource.Token);
返回重响应;
}
我在一篇帖子上看到,如果cookie有一个HttpOnly标志,它将无法工作。(见:) 这对我没有帮助,因为我无法从服务器端更改任何内容

谢谢

看看这个: