Jump to content

winhttp request fail


wpzzz
 Share

Recommended Posts

Then add COM error handler to your script to see detailed error message:

Global $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

Func ErrorHandler()
    $HexNumber = Hex($oMyError.number, 8)

    MsgBox(16, "CHYBA", "Došlo k chybě!" & @CRLF & @CRLF & _
            "Popis chyby: " & @TAB & $oMyError.description & @CRLF & _
            "Win. popis:" & @TAB & $oMyError.windescription & @CRLF & _
            "Číslo řádku: " & @TAB & $oMyError.scriptline & @CRLF & _
            "Číslo chyby: " & @TAB & $HexNumber & @CRLF & _
            "Objekt: " & @TAB & $oMyError.source, 0, $Form1)

    SetError(1)
EndFunc

Probably problem on your machine with DLL for " WinHttp.WinHttpRequest.5.1 " and ObjCreate fails.

Link to comment
Share on other sites

With your URL I got this detailed COM error message (from COM error handler) : Connection with server not established.

With different URL the same script works fine.

Global $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("GET","https://www.taiwanlotteryevent.com.tw",False)
$oHTTP.Send()

Func ErrorHandler()
    $HexNumber = Hex($oMyError.number, 8)

    MsgBox(16, "CHYBA", "Došlo k chybě!" & @CRLF & @CRLF & _
            "Popis chyby: " & @TAB & $oMyError.description & @CRLF & _
            "Win. popis:" & @TAB & $oMyError.windescription & @CRLF & _
            "Číslo řádku: " & @TAB & $oMyError.scriptline & @CRLF & _
            "Číslo chyby: " & @TAB & $HexNumber & @CRLF & _
            "Objekt: " & @TAB & $oMyError.source, 0, 0)

    SetError(1)
EndFunc

 

Edited by Zedna
Link to comment
Share on other sites

I thought the issue may be related to not having an appropriate User-Agent request header, but that wasn't an issue.  I tried it with the original URL, both with and without a User-Agent request header, and I got a valid response back each time. 

 

Here's the snippet I ran:

$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("GET","https://www.taiwanlotteryevent.com.tw",False)
;~ $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0")
$oHTTP.Send()

ConsoleWrite($oHTTP.StatusText & @CRLF)
ConsoleWrite(StringLeft($oHTTP.ResponseText, 1000) & @CRLF)

 

Here's the ConsoleWrite output I received:

OK
<!doctype html>
<html lang="zh-hant">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv ="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.5, user-scalable=1" />
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="icon" href="//www.taiwanlotteryevent.com.tw/images/16x16.ico" type="image/x-icon" />
<link rel="shortcut icon" href="//www.taiwanlotteryevent.com.tw/images/16x16.ico" type="image/x-icon" />
<title>???????? ??????</title> 
<meta property="og:title" itemprop="name" content="???????? ??????" />
    
<meta name="description" content="???????? ??????" />
<meta property="og:description" content="???????? ??????" />
<meta itemprop="description" content="???????? ??????" /> 
    
<meta property="og:image" content="//www.taiwanlotteryevent.com.tw/images/1200x630.png" />

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...