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.
This commit is contained in:
parent
ffac7545cf
commit
c8bbf7e789
1 changed files with 5 additions and 2 deletions
|
|
@ -57,13 +57,16 @@ int main() {
|
||||||
|
|
||||||
string name=pt.get<string>("firstName")+" "+pt.get<string>("lastName");
|
string name=pt.get<string>("firstName")+" "+pt.get<string>("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) {
|
catch(exception& e) {
|
||||||
*response << "HTTP/1.1 400 Bad Request\r\nContent-Length: " << strlen(e.what()) << "\r\n\r\n" << e.what();
|
*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
|
//GET-example for the path /info
|
||||||
//Responds with request-information
|
//Responds with request-information
|
||||||
server.resource["^/info$"]["GET"]=[](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
|
server.resource["^/info$"]["GET"]=[](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue