Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
545 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found the answer myself. It's quite simple:

http://www.jmarshall.com/easy/http/#proxies gives quite a brief and clear description how http proxies work.

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

...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...