使用套接字时的 AllowAutoRedirect 功能

AllowAutoRedirect Functionality when using sockets

我知道 HttpWebRequest 有一个参数可用于将 URL 重定向设置为 false (request.AllowAutoRedirect = False;)。

直接使用Socket连接是怎么做到的?

我没有任何代码可以展示,因为我刚刚开始一个项目的开发。

很遗憾,我需要坚持使用Socket 连接,不能使用HttpWebRequest、WebClient 或HTTPClient。 :(

没有套接字重定向这样的东西。

HTTP 重定向是指您连接到指定的服务器,发送您的 HTTP 请求,然后服务器发送一个 HTTP 响应,告诉您转到另一个 URL。那么你就去 URL 吧。

看起来像这样:

*** socket opened to example.com

*** client sends this part:
GET /some/address HTTP/1.1
Host: example.com

*** server sends this part:
HTTP/1.1 302 Found
Location: https://other.example.com/some_place?really=yes

*** socket closed to example.com

如果您禁用了自动重定向,这就是您的程序获得的响应。否则,HTTP 库继续运行:

*** socket opened to other.example.com

*** client sends this part:
GET /some_place?really=yes HTTP/1.1
Host: other.example.com

*** server sends this part:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 11

hello world

*** socket closed to other.example.com

如果您只是使用套接字,您将自己开始。