Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using json auth api to authenticate the user.
i am using my wordpress site hosted on 000webhost with https protocol.

When i am logging in i am getting this error message :
System.Net.WebException: The remote server returned an error: (401) Unauthorized

Please i need help,suggestions would be appreciated.

What I have tried:

//On button click

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.ContentType = "application/json";
            webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:28.0) Gecko/20100101 Firefox/28.0";
            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();
            }
Posted
Updated 16-Feb-17 5:48am
v2
Comments
Richard MacCutchan 16-Feb-17 11:50am    
At a guess, either your username or password, or both, are incorrect.
Member 12468321 16-Feb-17 11:52am    
@Richard, Both username and password are correct !
what should i do ?

I tested the URL and it worked on the web ..
Richard MacCutchan 16-Feb-17 12:18pm    
You probably need to remove those fields from the URL and use the Authorisation settings only. Other than that, you need to check with the owners of the website.
Member 12468321 16-Feb-17 12:25pm    
Could be using https instead of http cause a problem?
Richard MacCutchan 16-Feb-17 13:41pm    
Only one way to find out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900