Home > Net >  AllowAutoRedirect Functionality when using sockets
AllowAutoRedirect Functionality when using sockets

Time:11-04

I'm aware that HttpWebRequest has a parameter available to set URL redirection to false (request.AllowAutoRedirect = False;).

How is this done when using a Socket connection directly?

I don't have any code to show since I'm just starting down the road of development on a project.

Unfortunately, I need to stick to using Socket connections and cannot use HttpWebRequest, WebClient or HTTPClient. :(

CodePudding user response:

There is no such thing as a socket redirection.

An HTTP redirection is where you connect to the server specified, send your HTTP request, and server sends a HTTP response which tells you to go to a different URL instead. So then you go that URL instead.

It looks like this:

*** 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

if you have auto-redirect disabled, this is the response your program gets. Otherwise, the HTTP library keeps going:

*** 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

If you are just using sockets you will be doing this yourself to begin with.

  • Related