gpt4 book ai didi

c++ - 无法通过 cpp-netlib 发送发布请求

转载 作者:行者123 更新时间:2023-11-28 03:28:53 27 4
gpt4 key购买 nike

我在 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.

有什么想法吗?

最佳答案

查询参数不能包含空格,您必须对其进行 URL 编码。

空间是 %20 您的查询应该看起来像

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

关于c++ - 无法通过 cpp-netlib 发送发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com