Coldfusion - receive and parse JSON data

This is the first time I am writing cfc which will capture JSON data from an external web server that will host the information.

I’m working with a new service that can be configured to send unsuccessful transaction information JSON packet to me via HTTP POST to the URL specified by me.

I decided that I installed CFC with remote access to capture and deserialize JSON data into something that we could then act on. However, I cannot figure out how to set up a function in CFC to receive data?

I set the url: www.mydomain.com/com/processRemote.cfc?method=catchJSONdata&ReturnFormat=json

To verify this, I set up a simple test page that should publish session data:

<cfhttp result="result" method="post" url="http://www.mydomain.com/com/processRemote.cfc?method=catchJSONdata&ReturnFormat=json"> <cfhttpparam type="header" name="content-type" value="application/json"/> <cfhttpparam type="body" value="#serializeJSON(session)#"/> 

So, where did I get lost, is that the name cfargument that I would have in my cfc, which I would first store JSON data? I do not control a remote service that will send JSON data.

Thanks,

+8
json coldfusion cfc
source share
1 answer

If you read the content from the body of the HTTP request, you will not find it in the argument area - you need to extract it directly from the request:

 if (cgi.content_type EQ "application/json") { myData = deserializeJSON(ToString(getHTTPRequestData().content)); } 

I use the Taffy platform [1] to create such services (Disclaimer: I really helped write the part of the framework that handles this case).

[1] http://atuttle.github.com/Taffy/

+11
source share

All Articles