From c8bbf7e7893702835ec81f9394a5c239b2158520 Mon Sep 17 00:00:00 2001 From: Arash Date: Sun, 4 Sep 2016 10:48:11 +1000 Subject: [PATCH] Fixing response header Previously, running $.post( "json", JSON.stringify({ firstName: "John", lastName: "Smith", age: 25 }) ); would give an error message in Firefox browser console syntax error Now, this error message is not shown. --- http_examples.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/http_examples.cpp b/http_examples.cpp index 53aadf8..9fc88ae 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -57,13 +57,16 @@ int main() { string name=pt.get("firstName")+" "+pt.get("lastName"); - *response << "HTTP/1.1 200 OK\r\nContent-Length: " << name.length() << "\r\n\r\n" << name; + *response << "HTTP/1.1 200 OK\r\nContent-Length: " << name.length() << "\r\n" + << "Access-Control-Allow-Origin: *" << "\r\n" + << "Content-Type: application/json" << "\r\n\r\n" + << name; } catch(exception& e) { *response << "HTTP/1.1 400 Bad Request\r\nContent-Length: " << strlen(e.what()) << "\r\n\r\n" << e.what(); } }; - + //GET-example for the path /info //Responds with request-information server.resource["^/info$"]["GET"]=[](shared_ptr response, shared_ptr request) {