【发布时间】:2011-01-13 09:31:01
【问题描述】:
我正在尝试在我的项目中使用 cpp-netlib。我只需要创建一个 HTTP 代理,稍后我可以在其中插入一些功能。现在,我只需要监听请求,将请求发送到新站点,并将新请求的响应转发给第一个请求。
这是我目前的代码:
std::string ip = source(request);
http::client client;
std::ostringstream url;
url << "www.example.com/image.jpg";
http::client::request clientRequest(url.str());
http::client::response clientResponse = client.get(clientRequest);
response = server::response::stock_reply(server::response::ok);
response.headers = clientResponse.headers(); //This is not possible - not correct type or something
response.content = clientResponse.body();
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::multimap<_Kty,_Ty>' (or there is no acceptable conversion)
中的结果
对我正在使用的测试图像的请求会在响应中产生 19.4kb 的数据。如果我通过上述代码执行相同的请求(不复制标头),我会得到大约 4kb 数据的答案,浏览器会尝试将其显示为文本(默认标头)。它看起来确实像一张图片,即使是文本。
有熟悉 cpp-netlib-0.8 的人吗? response.content = clientResponse.body(); 是正确的方法吗?如何添加正确的标题?
cpp-netlib 中的模板太奇怪了,我现在无法理解!
谢谢...
【问题讨论】:
标签: c++ http networking