Page 1 of 1

Server module, changing contenttype

Posted: Wed Mar 22, 2017 10:43 pm
by HMJust
I have a bit of an issue. I need to return some JSON but because of the cross domain restrictions, I need to send the Access-Control-Allow-Origin header. I have ended up using a server module, like this:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_SRVM)

Srvroutine Name(LINKS) Response(#RESPONSE)
* #RESPONSE.ContentType := "application/json"
#RESPONSE.AddHeader( "Access-Control-Allow-Origin" "http://x.x.x.x" )
#RESPONSE.ContentString := ...
Endroutine

End_Com
There is of course more code than that :-)

That works fine, and I get something like

Code: Select all

HTTP/1.1 200 OK
Connection: close
Date: Wed, 22 Mar 2017 11:35:37 GMT
Server: Apache
Content-Type: text/plain; charset=iso-8859-1
Access-Control-Allow-Origin: http://x.x.x.x

[{"icon-url": "/images/wamlinks/icons/alien.3.png","link-url": "https://google.com/","title": "Google"}]
back. But the content type is of course wrong. So I try to change this by un-commenting the

Code: Select all

* #RESPONSE.ContentType := "application/json"
line above, and then I get

Code: Select all

HTTP/1.1 200 OK
Connection: close
Date: Wed, 22 Mar 2017 11:36:13 GMT
Server: Apache
Content-Type: application/json
Access-Control-Allow-Origin: http://x.x.x.x

žœ‰ƒ–•`¤™“z@a‰”‡…¢a¦”“‰•’¢a‰ƒ–•¢a“‰…•KóK—•‡k“‰•’`¤™“z@ˆ££—¢zaa‡––‡“…Kƒ–”ak£‰£“…z@Ç––‡“…GŸ
I have tried setting the charset but it did not help. Can anyone tell me what I am doing wrong?