- Home /
After updating to v2017.1, a www call returns "406 not acceptable"
Hi all
We used to use v5.6.1f where everything worked great. But after updating to v2017.1, the www call, is being rejected by the server with a "406 Not Acceptable" error.
We have tried to remove the security filter from the webserver thrugh the .htaccess file (even though this is not good manner). This removed the "406 Not Acceptable" error, but still no response was collected from the webserver.
Anyone who has an idea on what could be wrong? Do we need to add a header when doing the call to the web server? If so, how can we do that?
It must be mentioned, that no changes has been made to the webserver or the PHP script which is being called from the www!
Here is the code sample, which used to work in the previous version of Unity :)
IEnumerator LoadUserInfoRoutine() {
WWWForm form = new WWWForm ();
form.AddField ("unity_security", mySecurityCode);
form.AddField ("unity_method", "connect");
WWW www = new WWW(myURL, form);
yield return www;
if(www.error != null) {
Debug.Log (www.error);
} else {
response = www.text;
}
}
I don't think it's a bug - I think it's intentional - you need to set the headers before you use it.
Answer by plasticYoda · Dec 12, 2017 at 09:36 PM
I was using plain old www, and had the same problem. However, I needed to continue to use GET and not POST. To fix the error I used the following code to add the headers to the GET request.
Dictionary<string, string> ht = new Dictionary<string, string>();
ht["Accept"] = "*/*";
ht["Accept-Encoding"] = "gzip, deflate";
ht["User-Agent"] = "runscope/0.1";
WWW www = new WWW(url, null, ht);
yield return www;
Now the code works as it used to. @richardhaddadau - pretty sure the Unity guys changed stuff under the hood so the engine on PC/Mac no longer sets the headers to default values. The code still worked as expected on iOS/Android for me.
this worked flawlessly! thank you. I had to do WWW www = new WWW(url, form.data, ht);
Answer by Aelcyx · Sep 30, 2017 at 05:43 PM
I found that adding these headers made it work:
headers.Add("Accept", "*/*");
headers.Add("Accept-Encoding", "gzip, deflate");
headers.Add("User-Agent", "runscope/0.1");
I figured this out by going to hurl.it, trying the request there and then looking at the response data via browser tools.
Thank you for the answer, I will try it out and let you know if it works for us as well :)
You're welcome! I hope it works. Please mark the answer as accepted if so.
@Aelcyx, thanks for your answer; although it works, I still wonder why it's even needed. I mean, what's causing it? It seems like this only started occurring with Unity 2017.
Your answer
Follow this Question
Related Questions
WWWForm problem 1 Answer
wwwform send an array the right way! 0 Answers
Would a WWW to a PHP file return the computers Info? 0 Answers
PHP POST through $_REQUEST with WEBBUILD 1 Answer
Problem using WWW with PHP and MYSQL 3 Answers