How to connect a socket to an http server through proxy?

后端 未结 2 1323
失恋的感觉
失恋的感觉 2021-02-08 10:29

Recently I wrote a program using sockets in C, to connect to an HTTP server running locally and thereby to do requests to that.

That worked fine for me. After that I tri

2条回答
  •  执念已碎
    2021-02-08 10:34

    To use connections via proxy (or if they are implicitly proxy-fied), first you should connect to proxy, send a 'CONNECT' message with target host; proxy will establish connection and return you data.

    Here is in steps:

    1. open socket to proxy host
    2. send 'CONNECT http://www.google.com:80 HTTP/1.0\r\n\r\n' string
    3. wait for recv

    You must specify protocol (in our case is HTTP 1.0, non-chunked) with ending newline characters, so proxy knows how to communicate with end point.

    You can find details about CONNECT method at http://www.ietf.org/rfc/rfc2817.txt

提交回复
热议问题