我在Visual Studio 2010中使用cpp-netlib-0.9.4。我有一个函数make_header,它是这样的:
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;
}
get请求完全正常,类似于:
http::client client;
http::client::request* req = make_request_header(my_uri);
http::client::response res = client.get(*req);
但POST请求会抛出异常/ core-dump。我已经多次检查过它,它似乎每次都在chrome dev http客户端扩展上工作。我用于发帖请求的网址是:
http://myhost.com/commands?query=my query
在上面的例子中,我尝试
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.
任何想法为什么?
答案 0 :(得分:2)
查询参数不能包含空格,您必须对其进行URL编码。
查询的空格%20
应该是
http://myhost.com/commands?query=my%20query