UnityWebRequest setup
I'm new to web communication. I'm trying to get to the authenticated url with the following setup:
'Content-Type: application/json'
'Authorization: Basic '.base64_encode("$username:$password")
Here is my code:
string authenticate(string username, string password)
{
string auth = username + ":" + password;
auth = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
auth = "Basic " + auth;
return auth;
}
IEnumerator makeRequest()
{
string authorization = authenticate(username, password);
string url = "http://testweb14.webland.cz/api/user/login.php";
var request = new UnityWebRequest(url, "POST");
request.SetRequestHeader("Authorization", authorization);
request.SetRequestHeader("Content-Type", "application/json");
Debug.Log(request.url);
yield return request.SendWebRequest();
Debug.Log("Status Code: " + request.responseCode);
}
It returns "401" which means unauthorized. Can you tell me what's wrong?
Also is there a way to Debug.Log the whole request before sending so I see the whole header line of the request?
Thanks for your help.
Your answer
Follow this Question
Related Questions
Unity Web Request fails after exporting 0 Answers
How to make a Cross Origin Request work on Android 1 Answer
Hide .js file in project, make it only as a resource for HTML website. 0 Answers
Whats happened with the Asset Bundle Manager? 1 Answer
Checking correcly downloading asset bundle with web request.,Web Request and Asset Bundles 0 Answers