1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
1.5K views
by mike-r-7535 (13.8k points)
I am using JSON, and need to set the 'Content-Type' to 'application/json'.  How do I do this?

3 Answers

0 votes

In order to set the content-type of the http response, you will need to prepend your message content with actual http header for Content-Type.  So, you will want to set the content type something like this:

var contentType = "application/json";

var contentTypeLine = "http.header.Content-Type=" + contentType + "\r\n\r\n";

qie.postMessageResponse(contentTypeLine + message.getNode('/'));

Note: The prefix "http.header." before the header name (in this case Content-Type) followed by "=" and the header value, and a carriage return line feed (\r\n) are required.

 

See also:

Handling HTTP requests and responses

Posting Responses via qie.postMessageResponse() in a channel that uses an HTTP Listener source node

by mike-r-7535 (13.8k points)
edited by rich-c-2789
0 votes

Another example to add an http header to a message response is the following

qie.postMessageResponse('http.header.Access-Control-Allow-Origin=*\r\n' + message);

by brandon-w-8204 (34.1k points)
edited by rich-c-2789
0 votes

Here is an example of returning multiple headers.

They all should start with "http.header." and end with "\r\n"

Example:

qie.postMessageResponse('http.header.Access-Control-Allow-Origin= *\r\nhttp.header.Transfer-Encoding=chunked\r\n' + message);

by brandon-w-8204 (34.1k points)
edited by rich-c-2789
...