我正在尝试在我的一个项目中使用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中的模板怪异之处太多了,我现在无法理解它!
谢谢..。
发布于 2011-03-24 16:48:26
而不是使用:
response.content = clientResponse.body();正确的方法是:
std::string body_content = body(clientResponse);此外,当变量实际为clientResponse时,您使用response作为变量
有关更多示例,请阅读cpp-netlib v0.8 documentation
https://stackoverflow.com/questions/4678499
复制相似问题