Question

I'm trying to set Content-Type for URLRequest headers to "application/json". Here is the code:

var request:URLRequest = new URLRequest("http://localhost");
request.contentType =  "application/json; charset=UTF-8";

But as you can see on screenshot Content-Type is not in headers:

http://screencast.com/t/vHxHbSUOFM

But it's in request body:

http://screencast.com/t/irB16taO

How to make it right?

Was it helpful?

Solution

You need to use the URLRequestHeader class to set headers and push it. See below for a simple example,

var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var request:URLRequest = new URLRequest("http://localhost");
request.requestHeaders.push(hdr);

Hope this helped

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top