Jump to content

301 Response Text from winhttprequest


Recommended Posts

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.

 

 

 

 

 

Link to post
Share on other sites
22 hours ago, 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.

 

 

 

 

 

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)
;...

 

♡♡♡

.

eMyvnE

Link to post
Share on other sites

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By fenhanxue
      in msdn :https://msdn.microsoft.com/en-us/library/windows/desktop/aa384045(v=vs.85).aspx
      it says:

       
      I want to how how can i get the Return value (S_OK  or  error value )
      here is my codes as follow:
      Local $post_data = '123' Local $post_url = 'http://127.0.0.1/test.php' Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", $post_url, True) Local $Return_Value = $oHTTP.Send($post_data) $oHTTP.WaitForResponse(-1) Local $res = $oHTTP.responsetext MsgBox(0,'$Return_Value',$Return_Value);IT shows nothing ;why ? how can i get S_OK or error value ?  
    • By Xenobiologist
      Hello,
      I am using Loxone as the central "technology" for controlling my SmartHome. Now, I'm curious whether it is possible to use the webservice to get/set information in the Loxone miniserver.
      Anyone tried that already, or anyone who has got an idea what code to use?
      Thanks!
      Describtion of the webservice can be found here: https://www.loxone.com/enen/kb/web-services/
      Getting the mac address is working. The result looks the way it is described on the website.
      <?xml version="1.0" encoding="utf-8"?>
      <LL control="dev/cfg/mac" value="59:9F:99:90:89:C9" Code="200"/>
      All other stuff like getting the version - is not working.
      ;https://www.loxone.com/enen/kb/web-services/ #include <Crypt.au3> _Crypt_Startup() ; To optimize performance start the crypt library. Global Const $HTTP_STATUS_OK = 200 Global $user = 'xxx' Global $password = 'xxx' Global $ip = '192.168.178.77' Global $port = '50666' ;~ Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/mac', "password=" & _Crypt_HashData($password, $CALG_MD5)) Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/version', "password=" & _Crypt_HashData($password, $CALG_MD5)) ;~ Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/version') ;, "password=WeWantThisAsMd5") ;~ Global $MD5 = HttpGet('/dev/cfg/gateway') ;, "password=WeWantThisAsMd5") ConsoleWrite($MD5 & @CRLF) Func HttpPost($sURL, $sData = "") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", $sURL, False) If (@error) Then Return SetError(1, 0, 0) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($sData) If (@error) Then Return SetError(2, 0, 0) If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0) Return SetError(0, 0, $oHTTP.ResponseText) EndFunc ;==>HttpPost Func HttpGet($sURL, $sData = "") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") ;~ $oHTTP.Open("GET", $sURL & "?" & $sData, False) $oHTTP.Open("GET", $sURL & "?" & $sData, False) If (@error) Then Return SetError(1, 0, 0) $oHTTP.Send() If (@error) Then Return SetError(2, 0, 0) If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0) Return SetError(0, 0, $oHTTP.ResponseText) EndFunc ;==>HttpGet So long,
      Mega
×
×
  • Create New...