Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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# C语言中基于Cookie的身份验证#_C#_Rest_Authentication_Cookies_Restsharp - Fatal编程技术网

C# C语言中基于Cookie的身份验证#

C# C语言中基于Cookie的身份验证#,c#,rest,authentication,cookies,restsharp,C#,Rest,Authentication,Cookies,Restsharp,我有两个wpf应用程序的大问题 我们将服务器上的身份验证从基本http更改为基于cookie的身份验证,即令牌。这两个应用程序使用RestSharp使用旧的基本http身份验证对用户进行身份验证(一切正常): 更改为基于cookie后,我们从服务器获取状态代码403。我已经读到restsharp可以使用cookies。如何通过令牌编辑代码并使用基于cookie的身份验证对用户进行身份验证?谢谢所以我添加了以下内容来解决这个问题: client.FollowRedirects = false; /

我有两个wpf应用程序的大问题

我们将服务器上的身份验证从基本http更改为基于cookie的身份验证,即令牌。这两个应用程序使用RestSharp使用旧的基本http身份验证对用户进行身份验证(一切正常):


更改为基于cookie后,我们从服务器获取状态代码403。我已经读到restsharp可以使用cookies。如何通过令牌编辑代码并使用基于cookie的身份验证对用户进行身份验证?谢谢

所以我添加了以下内容来解决这个问题:

client.FollowRedirects = false; // very important in my case
... request.addParameters ...
... client.execute(request) ...

if (response.StatusCode == HttpStatusCode.Found)
{
      if (response.Cookies.Count == 1)
      {
             msg.Cookie = response.Cookies[0].Value;
             msg.ReturnValue = true;
      }
}
client.FollowRedirects = false; // very important in my case
... request.addParameters ...
... client.execute(request) ...

if (response.StatusCode == HttpStatusCode.Found)
{
      if (response.Cookies.Count == 1)
      {
             msg.Cookie = response.Cookies[0].Value;
             msg.ReturnValue = true;
      }
}