how to add proxy support to boost::asio?(如何为 boost::asio 添加代理支持?)
问题描述
在我的桌面应用程序中,我使用 boost::asio 添加了对各种互联网资源的访问.我所做的就是发送 http 请求(即映射图块服务器)并读取结果.我的代码基于 asio sync_client 示例.
In my desktop application I added access to various internet resources using boost::asio. All i do is sending http requests (i.e to map tile servers) and read the results. My code is based on the asio sync_client sample.
现在我收到客户的报告,他们在公司中运行代理而无法使用这些功能.在网络浏览器中,他们可以输入他们的代理地址,一切都很好.我们的应用程序无法下载数据.
Now i get reports from customers who are unable to use these functions as they are running a proxy in their company. In a web browser they can enter the address of their proxy and everything is fine. Our application is unable to download data.
如何为我的应用程序添加此类支持?
How can i add such support to my application?
推荐答案
我自己找到了答案.很简单:
I found the answer myself. It's quite simple:
http://www.jmarshall.com/easy/http/#proxies对 http 代理的工作原理进行了相当简洁明了的描述.
http://www.jmarshall.com/easy/http/#proxies gives quite a brief and clear description how http proxies work.
我所要做的就是将以下代码添加到 asio sync_client 示例示例中:
All i had to do is add the following code to the asio sync_client sample sample :
std::string myProxyServer = ...;
int myProxyPort = ...;
void doDownLoad(const std::string &in_server, const std::string &in_path, std::ostream &outstream)
{
std::string server = in_server;
std::string path = in_path;
char serice_port[255];
strcpy(serice_port, "http");
if(! myProxyServer.empty())
{
path = "http://" + in_server + in_path;
server = myProxyServer;
if(myProxyPort != 0)
sprintf(serice_port, "%d", myProxyPort);
}
tcp::resolver resolver(io_service);
tcp::resolver::query query(server, serice_port);
...
这篇关于如何为 boost::asio 添加代理支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 boost::asio 添加代理支持?
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01