I was trying to figure out the status code returned by my webpage, which most certainly is 301 (moved permanently), according to curl on the Linux subsystem, but using curl or the WebRequest object on powershell, it returns 200 (OK).
Why is this?
I was trying to figure out the status code returned by my webpage, which most certainly is 301 (moved permanently), according to curl on the Linux subsystem, but using curl or the WebRequest object on powershell, it returns 200 (OK).
Why is this?
It is because .NET and PowerShell are following redirects by default but curl does not do this. The default value of
HttpWebRequest.AllowAutoRedirect
is true and Invoke-WebRequest's MaximumRedirection default value is 5.To turn off automatic redirection via WebRequest:
or Invoke-WebRequest cmdlet:
Alternatively, use the -L flag to follow redirects in curl: