Having Trouble with Post to Server
Hey all! I am new to communicating with servers in Unity. Im struggling to figure out how to properly Post something to my server. Currently I'm successfully using Get with a Unescaped URL. However my Post returns a "Generic/unknown HTTP error" when I use the same Unescaped URL. Using a Escaped URL returns a "Cannot connect to destination host Network" error. The Unescaped URL is something like this : http://companyname-product-services.us-west-7.elasticbeanstalk.com/Authentication/login
I suspect its an issue with the URL since the rest of the code for posting seems pretty straight forward. Any ideas on why I am seeing these errors?
The following code is called when the user clicks a Unity Button:
public IEnumerator LoginUser()
{
string escapedURL = WWW.EscapeURL(url);
using (UnityWebRequest get = UnityWebRequest.Get(url))
{
yield return get.SendWebRequest();
ParseCSRF(get.downloadHandler.text);
CheckForNetworkErrors(get);
}
WWWForm form = new WWWForm();
form.AddField("username", username.text);
form.AddField("password", password.text);
form.AddField("_csrf", csrf);
using (UnityWebRequest post = UnityWebRequest.Post(url, form))
{
yield return post.SendWebRequest();
CheckForNetworkErrors(post);
}
}
public void CheckForNetworkErrors(UnityWebRequest www)
{
if(www.isNetworkError)
{
Debug.Log(www.error + " Network");
}
else if (www.isHttpError)
{
Debug.Log(www.error + " http");
}
else
{
Debug.Log("Form upload complete!" + www.downloadHandler.text);
}
}
Comment