C# 如何进行wordpress cookie认证?
我正在使用json auth api对用户进行身份验证 我正在使用我的wordpress网站,该网站以https协议托管在000webhost上 当我登录时,我收到以下错误消息:C# 如何进行wordpress cookie认证?,c#,json,xamarin,C#,Json,Xamarin,我正在使用json auth api对用户进行身份验证 我正在使用我的wordpress网站,该网站以https协议托管在000webhost上 当我登录时,我收到以下错误消息: System.Net.WebException: The remote server returned an error: (401) Unauthorized 我所尝试的: var webRequest =(HttpWebRequest)WebRequest.Create("https://mahdii.000we
System.Net.WebException: The remote server returned an error: (401) Unauthorized
我所尝试的:
var webRequest =(HttpWebRequest)WebRequest.Create("https://mahdii.000webhostapp.com/users/auth/generate_auth_cookie/?nonce=my_nonce&username=my_username&password=my_password");
webRequest.Method = "GET";
webRequest.ContentLength = 0; // added per comment
string autorization = "username" + ":" + "Password";
byte[] binaryAuthorization =System.Text.Encoding.UTF8.GetBytes(autorization);
autorization = Convert.ToBase64String(binaryAuthorization);
autorization = "Basic " + autorization;
webRequest.Headers.Add("AUTHORIZATION", autorization);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK) Console.WriteLine("{0}", webResponse.Headers);
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
string s = reader.ReadToEnd();
Console.WriteLine(s);
reader.Close();
}
请我需要帮助,建议将不胜感激
我很确定所有的url参数都是正确的 用于创建身份验证令牌的端点不应要求身份验证,因为这是负责验证用户的端点,这意味着它应允许未经身份验证的用户。一个建议:尝试将代码更改为使用HttpClient而不是WebRequest。很抱歉,我不知道如何正确编写代码。