0

I am using cpp-netlib-0.9.4 with Visual Studio 2010. I have a function make_header which is like this:

http::client::request* Interface::make_request_header(const string& uri) {
    string url = host_ + uri;
    string json_type = "application/json";
    http::client::request* req = new http::client::request(url);
    req->add_header(make_pair("X-AUTH-TOKEN", token_));
    req->add_header(make_pair("Content-Type", json_type));
    req->add_header(make_pair("Accepts", json_type));
    return req;
}

A get request works perfectly fine, which is something like:

http::client client;
http::client::request* req = make_request_header(my_uri);
http::client::response res = client.get(*req);

But a POST request throws an exception/core-dump. I have checked it multiple times otherwise and it seems to work every time on chrome dev http client extension. The URL I use for post request is:

http://myhost.com/commands?query=my query

In the above example, I try

http::client client;
http::client::request* req = make_request_header("http://myhost.com/commands?query=my query");
http::client::response res = client.post(*req);   // FAILS AT THIS STEP.

Any ideas why?

1 Answer 1

2

A query parameter can not contain spaces, you have to URL-encode it.

Space is %20 to your query should look like

http://myhost.com/commands?query=my%20query
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.