Jump to content

Recommended Posts

Posted

Hi Trancexx,  I'm trying to get information from a site that runs a little script in PHP where I register all HTTP request fields and I show it on screen.

If I run it from the browser it works it shows for each request:

13/10/2020-08:19:35pm IP:.... Port: 56578
Host: jcpetu.0fees.us
X-Forwarded-Proto: http
X-Real-IP: .....
X-Forwarded-For: ....
ERgbyuwRETHUHwefbuethWEGIHERGUHqwef8i: ....
Connection: close
DNT: 1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Language: en-US,en;q=0.9,es;q=0.8
Cookie: __test=9f9dde02f4033b8e6bfa7b79d5bd252f; sc_is_visitor_unique=rx9692532.1602627215.508ABCCDC33F4FC18EB91D379E737E1C.1.1.1.1.1.1.1.1.1

But when I use the following code I'm not able to receive the same info in the body, instead I got "This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support"

#include <array.au3>
#include <String.au3>
#include "WinHttp.au3"

Global $Host, $page, $sresp
$Host = "jcpetu.0fees.us"
$page = '/logme.php'

GET($Host, $page)
ConsoleWrite($sresp & @CRLF)

Func GET($Host, $page)
    $hOpen = _WinHttpOpen()
    If @error Then
        MsgBox(16, "Error", "Error initializing the usage of WinHTTP functions.")
        Return
    EndIf

    $hConnect = _WinHttpConnect($hOpen, $Host)
    If @error Then
        _WinHttpCloseHandle($hOpen)
        MsgBox(16, "Error", "Error specifying the initial target server of an HTTP request.")
        Return
    EndIf

    Local $req = _WinHttpOpenRequest($hConnect, "GET", $page)
    If @error Then     ;1 DllCall failed
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        MsgBox(16, "Error", "Error creating an HTTP request handle.")
        Return
    EndIf

    _WinHttpSendRequest($req)
    If @error Then
        _WinHttpCloseHandle($req)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        MsgBox(16, "Error", "Error sending specified request.")
        Return
    EndIf

    $sresp = ''
    _WinHttpReceiveResponse($req) ;Receive server response
    Switch @error
        Case 1
            _WinHttpCloseHandle($req)
            _WinHttpCloseHandle($hConnect)
            _WinHttpCloseHandle($hOpen)
            MsgBox(16, "Error", "Error waiting for the response from the server.")
            Return
    EndSwitch
    $sChunk = ""
    $sData = ""
    If _WinHttpQueryDataAvailable($req) Then
        While 1
            $sChunk = _WinHttpReadData($req)
            If @error Then ExitLoop
            $sData &= $sChunk
        WEnd
    Else
        MsgBox(16, "Error", "Site is experiencing problems.")
        Return
    EndIf

    $sresp = $sData
    _WinHttpCloseHandle($req)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndFunc   ;==>GET

If you can help me I'll apreciate it.

 

 

Posted (edited)
17 hours ago, jcpetu said:

Hi Trancexx,  I'm trying to get information from a site...

Are you looking for help from anyone, or are you looking for help specifically from trancexx, as your request suggests?

You've been a member since 2010 so I would have to assume that you meant what you wrote but I thought that I would ask just to make sure.  There are plenty of people that can help resolve WINHTTP/Web-related issues but probably haven't responded due to the way your request for assistance was written.

Edited by TheXman
Posted (edited)
19 hours ago, jcpetu said:

But when I use the following code I'm not able to receive the same info in the body, instead I got "This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support"

Actually, what you are seeing in the response from the server is the web page's source, including the scripts.

WINHTTP is not a browser so it does not have browser capabilities like the ability to process client-side scripts or to render HTML.  The URL in your example obviously has scripts in it that generate the information you are seeing in your browser.  Since WINHTTP can't process those scripts, the response you are getting is accurate, which is the web page's source not the output of the scripts.

Below is an example of using the WINHTTP COM object to do the same GET request as the one you did in your snippet above.  In my opinion, unless you need the extra functionality provided by the WINHTTP APIs, using the WINHTTP COM object is much simpler and straight forward.

#include <Constants.au3>

example()

Func example()
    Local $oComErr = Null, $oHttp = Null

    ;Set up COM error handler
    $oComErr = ObjEvent("AutoIt.Error", com_error_handler)
    #forceref $oComErr

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

    With $oHttp
        ;Set up and send request
        .Open("GET", "http://jcpetu.0fees.us/logme.php")
        .Send()

        ;If response code is not 200 (OK), then exit with message
        If .Status <> 200 Then Exit MsgBox($MB_ICONWARNING, "WARNING", "BAD HTTP RESPONSE" & @CRLF & @CRLF & .Status & " " & .StatusText)

        ;Display response code and response
        ConsoleWrite(StringFormat("Response Status: %s (%s)", .Status, .StatusText) & @CRLF)
        ConsoleWrite(.ResponseText & @CRLF)
    EndWith
EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("GetLastError()     : %s", .LastDllError) & @CRLF
    EndWith

    ConsoleWrite($sErrMsg)
    MsgBox($MB_ICONERROR+$MB_TOPMOST, "COM ERROR", $sErrMsg)

    Exit
EndFunc

 

Edited by TheXman
Added COM example
Posted
20 hours ago, jcpetu said:

site that runs a little script in PHP where I register all HTTP request fields and I show it on screen.

are you the author of the php script as well?

Code hard, but don’t hard code...

Posted

TheXman, I keep receiving the same message:

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("dfed4ebac28edb41645ed3f000967481");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://jcpetu.0fees.us/logme.php?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

JockoDundee

yes I created the PHP.

 

Posted (edited)
25 minutes ago, jcpetu said:

TheXman, I keep receiving the same message

Did you not read my post?  :huh2::)  You will continue to get the same response using WinHttp (COM or API) because it doesn't have the ability to process client-side scripting. 

I just provided an example using COM to show you what the same request would look like and how much simpler it is to use than APIs, which is what the WINHTTP UDF is based on.

Given JackoDundee's question, he's probably going to suggest an alternate solution which would be to use server-side scripting to render the information in the response instead of using client-side scripting.  ;)  It looks like most of the information you are trying to display is coming from the request header.  So most, if not all, of the information should be available to render using server-side scripting.

Edited by TheXman
Posted

TheXman, Ok I got it.

After a while, and a lot of trial and error I found that website is not rendering my PHP output when the request comes via TCP request and it is so because of the type of free service of my hosting site.

I moved my site to another free hosting and now it works with both Winhttp and COM objects and without changing my PHP.

Thanks a lot for your help.

 

Posted

I'm glad that you were able to get it all sorted out.   :thumbsup:

Posted
2 hours ago, TheXman said:

Given JackoDundee's question, he's probably going to suggest an alternate solution which would be to use server-side scripting to render the information in the response instead of using client-side scripting.

Precise presumptive prescience :)

Code hard, but don’t hard code...

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