WWW class and HTTP Headers

Hi All,

Does anyone know if the WWW API will allow setting the HTTP headers for GET requests?


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

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);

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.


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.

The WWW class does not allow this. UniWeb does.