Python socket module. Connecting to an HTTP proxy then performing a GET request on an external resource

后端 未结 2 695
梦毁少年i
梦毁少年i 2021-01-07 06:36

To begin with, I understand there are other modules such as Requests that would be better suited and simpler to use, but I want to use the socket module to better understand

2条回答
  •  鱼传尺愫
    2021-01-07 07:14

    To make a HTTP request to a proxy open a connection to the proxy server and then send a HTTP-proxy request. This request is mostly the same as the normal HTTP request, but contains the absolute URL instead of the relative URL, e.g.

     > GET http://www.google.com HTTP/1.1
     > Host: www.google.com
     > ...
    
     < HTTP response
    

    To make a HTTPS request open a tunnel using the CONNECT method and then proceed inside this tunnel normally, that is do the SSL handshake and then a normal non-proxy request inside the tunnel, e.g.

     > CONNECT www.google.com:443 HTTP/1.1
     >
     < .. read response to CONNECT request, must be 200 ...
    
     .. establish the TLS connection inside the tunnel
    
     > GET / HTTP/1.1
     > Host: www.google.com
    

提交回复
热议问题