Retrieving json with WWW raises 415 Unsupported Media Type

Hey Guys,

I’ve been using Uniweb for my web requests, but I had problem with iOS8 so I’m changing it back to plain WWW. I used it like so and it has worked when my content type is “application/x-www-form-urlencoded”.

I used it like so :

string myUrl ="someUrl.com/someFolder"
WWWForm form = new WWWForm();
form.AddField("Content-Type", "application/x-www-form-urlencoded");
form.AddField("Content-length", "0");

var headers = new Hashtable();
headers.Add("WWW-Authenticate","xxxxx");

WWW request = new WWW(url,form.data,headers);

It works fine but when I use it for content “application/json”, I get the error 415 Unsupported Media Type.
I read that I missed the Header “Accept”, “application/json” so I tried to add it to the form and it didn’t work than I added it to the headers and it didn’t worked either.

Does anyone have an idea ?

Thanks a lot.

I have solved this problem.
You can try like this.
//First , you need to convert your post data into byte.

WWWForm form=new WWWForm();
string body=LitJson.JsonMapper.ToJson( /here is you data/ );
byte data=System.Text.Encoding.UTF8.GetBytes(body);

//then set the headers
Dictionary headers=form.headers;
headers[“Content-Type”]=“application/json”;

WWW www=new WWW(url,data,headers);

You can try this.I have successed~ I feel good . hahaha