我在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客户端扩展上工作。我用于post请求的URL是:
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.你知道为什么吗?
发布于 2012-10-31 14:43:18
查询参数不能包含空格,您必须对其进行URL编码。
Space is %20 to your query应该看起来像这样
http://myhost.com/commands?query=my%20queryhttps://stackoverflow.com/questions/13150649
复制相似问题