我在 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 请求会引发异常/核心转储。否则我已经检查了多次,它似乎每次都在 chrome dev http 客户端扩展上工作。我用于发布请求的 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.
任何想法为什么?