Jump to content

HttpQueryInfo & DllCall


Recommended Posts

I am trying to POST some data to a website, but it seems as in order to correctly do it I need to get the header information and manage the cookies.

http://msdn.microsoft.com/library/default....tpqueryinfo.asp

Func _HttpQueryInfo($l_Request) 
    Local $v_Struct = DllStructCreate('char[256]')
    DllStructSetData($v_Struct, 1, "")
    Local $ai__HttpQueryInfo = DllCall('wininet.dll', 'long', 'HttpQueryInfo', 'long', $l_Request, 'long', 22, 'ptr', DllStructGetPtr($v_Struct), 'long', 0, 'int', 0)
EndFunc

The return value for HttpQueryInfo is 0 (meaning an error). I don't know how to setup a buffer to take in the headers. Any help would be great. I took the struct idea from wouter, but I have no idea how to use them in theory.

$l_Request is the handle returned by HttpOpenRequest

Link to comment
Share on other sites

  • 1 year later...

Did you find out how it should work, ParoXsitiC? Or maybe anyone else?

VB-example of HttpQueryInfo working:

http://www.tek-tips.com/faqs.cfm?fid=4579

Delphi-example of HttpQueryInfo working:

http://www.cryer.co.uk/brian/delphi/winine..._isurlvalid.htm

Anyone?(A)

Thanks in advance...=)

//Edit #3:

I made some progress:

Func _HTTPQueryInfo($l_Request)
    Local $ai__HttpQueryInfo, $s_Buf = ''
    Local $v_Struct = DllStructCreate('udword')
    DllStructSetData($v_Struct, 1, 1)
    $i = 0
    For $i = 0 To 1
        $ai__HttpQueryInfo = DllCall($dll, 'int', 'HttpQueryInfo', 'long', $l_Request, 'int', 22, 'str', '', 'ptr', DllStructGetPtr($v_Struct), 'dword', 0)
        $s_Buf &= $ai__HttpQueryInfo[3]
    Next
    Local $File = FileOpen(@ScriptDir & '\temp\headers.txt', 2)
    FileWriteLine($File, $s_Buf)
    FileClose($File)
EndFunc

It gives me this header:

HTTP/1.1 200 OK

ETag: "390241-3744-463470b1"

Content-Length: 14148

Content-Type: application/zip

Last-Modified: Sun, 29 Apr 2007 10:17:21 GMT

But still not the header(s) that Firefox shows me in LiveHTTPHeader.

I want to recieve this header:

HTTP/1.x 302 Found

Date: Sun, 16 Mar 2008 11:13:32 GMT

Server: Apache/1.3.41 (Unix) mod_deflate/1.0.19 mod_fastcgi/2.4.2 PHP/5.2.5 rus/PL30.22

X-Powered-By: PHP/5.2.5

Location: /map/filename.zip

Connection: close

Content-Type: text/html; charset=windows-1251

Vary: accept-charset, user-agent

Content-Length: 0

Anyone, please? Edited by Noobster24
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

  • 6 months later...

You could get header "manually" (been writting about this):

Dim $sURL = 'http://www.autoitscript.com/forum/index.php?showtopic=30409'

Dim $www = URLGetHeader($sURL)
MsgBox(0,"Header", $www)

Func URLGetHeader($URL)

    $URL = StringRegExpReplace($URL, '\A(http://|https://)(.*?)/?\Z', '$2') 
    
    TCPStartup() 
    
    Local $dom = StringRegExpReplace($URL, '\A(.*?)/.*', '$1') 
    Local $ip = TCPNameToIP($dom) 
    If $ip = "" Then Return -1
    
    Local $get = StringRegExpReplace($URL, '\A(.*?)/(.*)', '$2') 
    If $get = $dom Then $get = '' 
    
    Local $header = 'GET /' & $get & ' HTTP/1.1' & @CRLF _
             & 'User-Agent: Test' & @CRLF _
             & 'Host: 127.0.0.1' & @CRLF & @CRLF 

    Local $socket = TCPConnect($ip, 80) 
    If $socket = -1 Then Return -2 
    
    TCPSend($socket, $header) 
    
    Local $rcv, $out, $x, $sw, $r, $lenght
    
    While 1
        
        If $rcv <> '' Then
            $x = 1
        EndIf
        
        $rcv = TCPRecv($socket, 1024) 
        
        $out &= $rcv ; not needed, but who knows
        
        If $x = 1 Then
            If $rcv = '' Then
                $sw += 1
                If $sw = 10000 Then ExitLoop
            Else
                $sw = 0
            EndIf
        EndIf
        
        Local $loc = StringInStr($rcv, @CRLF & @CRLF)
        If $loc <> 0  Then 
            $out = StringLeft($out, $loc)
            ExitLoop
        EndIf
        
    WEnd
    
    TCPCloseSocket($socket) 
    TCPShutdown() 
    
    Return $out
    
EndFunc

Also, read http://www.autoitscript.com/forum/index.php?showtopic=77503 about wininet.dll

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

trancexx

Thank you for the solution but i wonder if you know about a way to get the headers with the use of wininet.dll

Maybe you can help me and answer my question at the post you stated above

http://www.autoitscript.com/forum/index.php?showtopic=77503&view=findpost&p=581630

I'm doing benchmarks test for all the ways i knwo to interact with website..

For now i've manged to test curl and winhhtp object.

I'm now stuck with this wininet.dll because I dont even know how to call a dll...

After that i'll try to benchmark autoit tcp commands..

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