Roul
Roul

Reputation: 965

Return JSON data in response in ColdFusion

I'm working in ICIMS API. I need to return JSON data and some specific data in header in a cfm page call by ICIMS server.

Here is the response should be:

Response to the Work Flow Status Change PUSH event to the platform:

HTTP/1.1 303 See Other
Location: http://xx.xx.xx.xx:8085/selectpackage?systemHash=101
Content-Type: application/json
{
"userMessage":"Confirm or modify package.",
}

Thanks in advance.

Answer:

> <cfset contentString = '{"userMessage": "Confirm or modify package."}'
> />
> 
> <cfheader name="Location"
> value="http://xx.xx.xx.xx:8085/selectpackage?systemHash=101" />
>     <cfcontent type="application/json" variable="#toBinary( toBase64( contentString ) )#" />

Upvotes: 10

Views: 10668

Answers (1)

Alex Baban
Alex Baban

Reputation: 11732

<cfheader 
    statusCode = "303"
    statusText = "See Other">

<cfheader 
    name="Location" 
    value="http://xx.xx.xx.xx:8085/selectpackage?systemHash=101">

<cfheader 
    name="Content-Type" 
    value="application/json">

<cfset foo = structNew()>
<cfset foo["userMessage"] = "Confirm or modify package.">

<cfoutput>#serializeJSON(foo)#</cfoutput>  

Upvotes: 15

Related Questions