- Home /
WWW class and HTTP Headers
Hi All,
Does anyone know if the WWW API will allow setting the HTTP headers for GET requests?
Thanks
Answer by Bunny83 · Dec 06, 2011 at 01:57 PM
No, it doesn't. If you read the docs on WWW you may have noticed that only the constructor with a single URL string will produce a GET request. All other versions use POST.
edit
I just had a look into the UnityEnigne.dll and it seems the single string argument constructor just uses WWW(url,null,null). So basically all use the same constructor. Now it depends on how Unity determines if it should send a POST or GET. Maybe they just look for the postData != null. So if you pass null it might send the request via GET. You have to try it yourself.
If you have new information, feel free to add an answer yourself that clears things up for others.
it didnt work. once i had a header value it changed to post. but thanks
That's a pity. Well, the only other way would be to use .NET / $$anonymous$$ono functions for the request. If you build for the webplayer, make sure the class / function is available and you provide a crossdomain-policy file.
I just had a look into the UnityEnigne.dll
@Bunny83, how did you looked inside it?
Answer by delsolu · Sep 19, 2013 at 06:22 AM
The key is leaving "postData" parameter to null. From Unity3D WWW reference
The WWW class will use GET by default and POST if you supply a postData parameter.
So this one works for me:
var form = new WWWForm();
var headers = new Hashtable();
headers.Add("Header_key", "Header_val");
www = new WWW("http://localhost/getpostheaders", null, headers);
yield return www;
Debug.Log("2. " + www.text);
Answer by Simon Wittber · Feb 08, 2012 at 03:20 AM
The WWW class does not allow this. UniWeb does.
Using UniWeb comes with all sorts of other problems, such as having to setup a SocketPolicy listener on the server which requires another open port on the backend.
If you have control over your backend, I'd recommend changing it to support the given http endpoint using POST as well. It sucks and breaks the Restfulness if you'r backend api.
Unity not supporting custom headers for GETs really sucks.
Your answer
Follow this Question
Related Questions
WWW class does not work 1 Answer
Unable to call external API (IBM Watson) via HTTP request? 1 Answer
Calling API via proxy 0 Answers
Is pulling and parsing XML data from 3rd party API call possible? 1 Answer
http request over an https webgl 1 Answer