Poppe76 Poppe76 - 1 year ago 109
JSON Question

FlashDevelop receives XML, Flash Pro receives JSON

I'm getting a data feed from a client's supplier.

Documention says that I can get the feed both in XML and in JSON, but that the default is XML. To get JSON I have to set a header Accept:application/json and remove Accept:application/xml header.

I have not set nor removed any headers in my code.

I'm using a normal URLLoader to load the feed.

When I navigate to the feed url in a browser, I get XML.

When I run my code in FlashDevelop, I get XML.

When I run the exact same code in Flash Pro, I get JSON.

Does anyone have any idea what is causing this in Flash Pro? Any hidden setting that can be changed?

URLRequest.method has no impact. Debug mode or not has no impact.

I'm stomped.

---------code I tried------------

var header:URLRequestHeader = new URLRequestHeader("Accept", "application/xml");
var headers:Array = [];
urlReq.requestHeaders = headers;
urlReq.method = URLRequestMethod.POST;

Answer Source

Different clients/applications have different defaults. Different versions of the flash/air runtime may have different defaults for the accept type.

If you need consistency, then you should explicitly set the accept type in your request:

urlrequest.requestHeaders = [new URLRequestHeader("Accept", "application/json")];

This should ensure you get JSON back in both IDE's in whatever version of the runtime you're using.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download