我正在使用json auth api对用户进行身份验证。
我使用https协议在000webhost上托管的wordpress网站。
当我登录时,我收到此错误消息:
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();
}
我需要帮助,建议将不胜感激。
我很确定所有网址参数都是正确的!