开发者

How to connect to remote server with proxy in win32 API?

// try to connect to server
if ((Status = connect(sock_server, &serverSockAddr, sizeof(serverSockAddr))) < 0)
{
    SockSend(sock_client, "404 Host Not Found\n\n", 20);
    SockClose(sock_client);
    return 1;
}

// send client's req to server
SockSend(sock_server, buf, strlen(buf));

The开发者_如何学编程 above is the code to connect to remote server without proxy,how can I do it with proxy?


The InternetOpen function allows specifying a proxy. Next the InternetConnect function can be called. InternetConnect gives you a small selection of server ports to connect to. I don't see any way to reach an arbitrary port number on the server.


Using the Winsock API for this type of thing is almost never the right choice. Using WinHTTP or WinINET is a much simpler way to go, and will allow you to avoid writing thousands of lines of code.


I assume HTTP proxy.

You connect to the proxy and then issue the GET or whatever HTTP you want to do. You will need to make sure the GET has domain + resource like

GET stackoverflow.com/ HTTP/1.0
Host: stackoverflow.com

RFC docs for HTTP 1.0 and 1.1 will detail more. For other types of proxies you will need to provide some feedback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜