I am using WWWForm
for HTTP GET and POST. In My Game URL credentials are added, and data GET and POST as Json
format.
I can get the details using credentials on Browser, But i cannot access details using WWWForm
. First I was facing 401 Unauthorised problem. Then i added header like
Dictionary<string, string> headers = form.headers;
headers["content-type"] = "application/json";
headers["Authorization"] = "Basic " + System.Convert.ToBase64String(Encoding.Default.GetBytes(username+":"+password));
After that i don’t have getting 401 Unauthorised problem . Know I have getting 400 Bad Request
Here is my Code.
IEnumerator ConnectToServer2(string username,string password)
{
WWWForm form = new WWWForm();
Dictionary<string, string> headers = form.headers;
headers["content-type"] = "application/json";
headers["Authorization"] = "Basic " + System.Convert.ToBase64String(Encoding.Default.GetBytes(username+":"+password));
// form.AddField( "Book_Name", "Night%20at%20call%20centre" );
form.AddField( "Book_Name", "Night at call centre" );
form.AddField( "Book_Part", "First" );
form.AddField( "Sequence", "1" );
// form.AddField( "username", username );
// form.AddField( "password", password );
byte[] rawData = form.data;
// Post a request to an URL with our custom headers
WWW www = new WWW(bookViewUrl, rawData, headers);
yield return www;
if (www.error != null) {
Debug.Log (www.error);
} else {
Debug.Log (www.text);
}
//.. process results from WWW request here...
}
Thanks in advance.