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 添加代理支持?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
