我正在尝试使用 boost::beast 来通过 HTTP 与服务器通信。
我在客户端工作,想发送一个至少包含以下标题字段的请求:“X-API-SIGNATURE”。
我正在按如下方式创建请求:
http::request<http::dynamic_body> request;
request.version(11);
request.method(http::verb::get);
request.target("/test");
request.set(http::field::host, host_);
request.set("X-API-KEY", key_);
request.set("X-API-SIGNATURE", signature_);
int count_Header_Field_X_API_SIGNATUR = request.count("X-API-SIGNATURE"); // This is 1.
int count_Header_Field_X_API_Bla = request.count("X-API-BLA"); // This is 0.
我发送请求如下:
boost::beast::http::async_write(
*socket_,
request,
std::bind(
&Testclass::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
之后,我得到来自服务器的响应,报告我一个错误:
{"errors":[{"message":"Missing header: X-API-SIGNATURE","code":1,"field":"X-API-SIGNATURE"}],"credits":8}
我不明白为什么服务器无法识别我之前插入请求中的“X-API-SIGNATURE”标头字段。
我做错了什么?