Sidebar

How do I set the 'Content-Type' in an HTTP Response?

0 votes
687 views
asked Aug 13, 2014 by mike-r-7535 (13,830 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 = "Content-Type: " + contentType + "\r\n";

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

*Note that not all HTTP headers can be set this way.

answered Aug 13, 2014 by mike-r-7535 (13,830 points)
0 votes

The way to add http headers to a message response is the following

qie.postMessageResponse('httpHeader:Access-Control-Allow-Origin: *\r\n' + message);

answered May 8, 2017 by brandon-w-8204 (33,170 points)
0 votes

Here is an example of returning multiple headers.

They all should start with httpHeader: and end with /r/n

Example:

qie.postMessageResponse('httpHeader:Access-Control-Allow-Origin: *\r\nhttpHeader:Transfer-Encoding: chunked\r\n' + message);

answered Dec 5, 2022 by brandon-w-8204 (33,170 points)
...