Jump to content

Bad certificate and HTTP Get request

Recommended Posts

Hi community

I am trying to get some basic information from printers in my network. For this I use such code

#include <Constants.au3>

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

http_get_example ( "hostname_to_check" )

Func http_get_example ( $sHostname )
    Local $oHttp = Null, $oComErr = Null

    ;Register COM Error Handler
    $oComErr = ObjEvent("AutoIt.Error", com_error_handler)
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to register COM error handler - @error = " & @error)

    ;Create HTTP COM object
    $oHttp = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to create HTTP COM object - @error = " & @error)

    With $oHttp
        ;Open GET request
        .Open("GET", "http://" & $sHostname & ".enedis-grdf.fr/", False )
        If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.WinDescription))

        ;Send request
        If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.Description))

        ConsoleWrite(StringFormat("HTTP Status: %s %s", .Status, .StatusText) & @CRLF)

        ;If http status code not 200
        If .Status <> 200 Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("HTTP Status Code = %s %s", .Status, .StatusText))

        ;Display response
        ConsoleWrite(@CRLF & "HTTP Response:" & @CRLF)
        ConsoleWrite(.ResponseText    & @CRLF)

Func com_error_handler($oError)
    With $oError
        ConsoleWrite(@CRLF & "COM ERROR DETECTED!" & @CRLF)
        ConsoleWrite("  Error ScriptLine....... " & .scriptline & @CRLF)
        ConsoleWrite("  Error Number........... " & "0x" & Hex(.number) & " (" & .number & ")" & @CRLF)
        ConsoleWrite("  Error WinDescription... " & StringStripWS(.windescription, $STR_STRIPTRAILING) & @CRLF)
        ConsoleWrite("  Error Description...... " & StringStripWS(.description   , $STR_STRIPTRAILING) & @CRLF)
        ConsoleWrite("  Error RetCode.......... " & "0x" & Hex(Number(.retcode)) & " (" & Number(.retcode) & ")" & @CRLF)
    Return ; Return so @error can be trapped by the calling function

On some printers it runs flawlessly, on some newer, I've got an error

  Error ScriptLine....... 25
  Error Number........... 0x80020009 (-2147352567)
  Error WinDescription... An exception has occured (translated from french : Une exception s’est produite. )
  Error Description...... The certificate authority is not valid or correct (translated from french : L’autorité de certification n’est pas valide ou correcte)
  Error RetCode.......... 0x80072F0D (-2147012851)

Manually, I can bypass this warning, this is ths usual error when you browes an http site without 's', certificate error
"I aknowledge teh risk, I anyway wnat to browe at my own risk bla bla"

Is there a way to bypass such erro and follow browsing even if http and not https mode ?


Link to comment
Share on other sites

Thank you !

Now that problem is solved, I'd like to load from this printer Lexmark the specific page of network configuration in order to catch MAC address
It seems to be accessible via JS
Is there a way to do this with winhttprequest ?

The tag that lead to this is  :

<li id="Settings-Reports-link">
<a class="navSection link navLink" href="#/Settings/Reports" 
tabindex = "202"

Here the page I want to access


Here the HTML code


Edited by Ebola57
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

  • Recently Browsing   0 members

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