Jump to content

Recommended Posts

Posted

Dear people,

How do circumnavigate a 301 response? Up to now a 200 was returned and everyone was happy.

; Creating the object
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

   $oHTTP.Open("POST", $url, False)
   ;$oHTTP.Open("GET", $address, False)
   ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

; Performing the Request
   $oHTTP.Send()

; Download the body response if any, and get the server status response code.
   $HTML = $oHTTP.ResponseText
   $oStatusCode = $oHTTP.Status
   log_this("send request response status=" & $oStatusCode)

Now my $HTML string is just:

<html>

<head><title>301 Moved Permanently</title></head>

<body bgcolor="white">

<center><h1>301 Moved Permanently</h1></center>

<hr><center>nginx</center>

</body>

</html>

which is rude. Answers on a postcard please.

 

 

 

 

 

Posted
  On 9/4/2019 at 2:24 PM, DazSpaz said:

a 301 response

Expand  

... is probably a redirection, so you might try to get the headers and look for the new location
Personally as I am extremely lazy, in such cases I use curl which with option -L  does the job for me :idiot:

Posted

It does... I think the site has got clever. On View page source, all the data is there. I assume the HTTP request doesnt carry all the sender info from using actual browser thus the site gives a technical middle finger.

Posted
  On 9/4/2019 at 2:24 PM, DazSpaz said:

Dear people,

How do circumnavigate a 301 response? Up to now a 200 was returned and everyone was happy.

; Creating the object
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

   $oHTTP.Open("POST", $url, False)
   ;$oHTTP.Open("GET", $address, False)
   ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

; Performing the Request
   $oHTTP.Send()

; Download the body response if any, and get the server status response code.
   $HTML = $oHTTP.ResponseText
   $oStatusCode = $oHTTP.Status
   log_this("send request response status=" & $oStatusCode)

Now my $HTML string is just:

<html>

<head><title>301 Moved Permanently</title></head>

<body bgcolor="white">

<center><h1>301 Moved Permanently</h1></center>

<hr><center>nginx</center>

</body>

</html>

which is rude. Answers on a postcard please.

 

 

 

 

 

Expand  

Redirection policy can be set per http object. Default should be to follow redirects but maybe you or someone with enough privileges changed it on system level. Anyway, try it like this:

Const $WinHttpRequestOption_EnableRedirects = 6

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

; Check default WinHttpRequestOption redirection setting
$vDefaultSetting = $oHTTP.Option($WinHttpRequestOption_EnableRedirects)
ConsoleWrite("Default setting is: " & $vDefaultSetting & @CRLF)

; Enable redirects
$oHTTP.Option($WinHttpRequestOption_EnableRedirects) = True

; Check current setting
$vCurrentSetting = $oHTTP.Option($WinHttpRequestOption_EnableRedirects)
ConsoleWrite("Current setting is: " & $vCurrentSetting & @CRLF)

$oHTTP.Open("POST", $url, False)
;...

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...