- Home /
Posting to server using WWW will cause server to hang
I've been trying to do a simple post to a server, but it'll always hang or give me an error. I don't need to send data to post, so if I send an empty WWWForm, it'll throw an error. If I add data, it'll freeze during the yield.
Here is the code:
public GameObject SomeFunction() {
string url = "http://myurl";
WWWForm form = new WWWForm();
form.AddBinaryData("dummy", new byte[1]);
WWW www = new WWW(url, form);
StartCoroutine(WaitForRequest(www));
}
IEnumerator WaitForRequest(WWW www) {
Debug.Log ("Yielding");
yield return www;
Debug.Log ("Finished");
// Check for errors
if (www.error == null) {
Debug.Log("WWW Ok!: " + www.text);
} else {
Debug.Log("WWW Error: "+ www.error);
}
}
Right now it freezes during yield return www, am I missing something? I don't need to send my server anything to post and I'm sure that the API is working for the server.
Your title says that the server fails... so this may not be a Unity issue. If your testing outside of Unity shows that the server always works, then I guess comparing the request that Unity makes to the one you make will help you out.
I believe it is how we set the server up, since I can post to other IP's with the same code and it'll work. So I don't think it's a problem with my code anymore. I'll update when the server is hooked up properly.
Your answer
![](https://koobas.hobune.stream/wayback/20220611231526im_/https://answers.unity.com/themes/thub/images/avi.jpg)