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 添加代理支持?


- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01