如何为 boost::asio 添加代理支持? [英] how to add proxy support to boost::asio?

查看:24
本文介绍了如何为 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 添加代理支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆