如何为boost :: asio添加代理支持?

RED*_*AIR 8 c++ proxy boost-asio

在我的桌面应用程序中,我使用boost :: asio添加了对各种Internet资源的访问.我所做的就是发送http请求(即映射磁贴服务器)并读取结果.我的代码基于asio sync_client示例.

现在,我收到了无法使用这些功能的客户的报告,因为他们在公司中运行代理.在Web浏览器中,他们可以输入代理的地址,一切都很好.我们的应用程序无法下载数据.

如何为我的应用程序添加此类支持?

RED*_*AIR 5

我自己找到了答案.这很简单:

http://www.jmarshall.com/easy/http/#proxies 给出了一个简短而清晰的描述http代理如何工作.

我所要做的就是将以下代码添加到asio sync_client示例示例中:

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);

...
Run Code Online (Sandbox Code Playgroud)