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

#1 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 09 November 2008 - 10:28 PM

*
POPULAR

The other day mikeytown2 posted one post in HTTP UDF's thread that got me thinking if there is better (different) method to send requests through the HTTP protocol to HTTP servers.

There is Winhttp.dll that ships with windows and that is its main purpose. I couldn't find any examples of using this dll in AutoIt, so I came up with this.

Microsoft about Windows HTTP Services:
Microsoft Windows HTTP Services (WinHTTP) provides developers with an HTTP client application programming interface (API) to send requests through the HTTP protocol to other HTTP servers...
.. blah, blah, and so on...


This is an example of getting page header:
AutoIt         
#include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Open needed handles Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "msdn.microsoft.com") ; Specify the reguest: Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "en-us/library/aa384101(VS.85).aspx") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header ; Clean _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Display retrieved header MsgBox(0, "Header", $sHeader)


Everything you need to be able to use this UDF can be found at WinHttp site.



Remember, basic understanding of the HTTP protocol is important to use this interface.



ProgAndy, trancexx



WinHttp.au3 is completely free and no one has right to charge you for it. That's very important.
If you feel WinHttp.au3 was helpful to you and you wish to support my further work you can donate to my personal account via PayPal address: trancexx at yahoo dot com
I will appreciate that very much. Thank you in advance! :kiss:

Edited by trancexx, 06 May 2013 - 07:11 AM.

  • yahaosoft, ileandros, header127 and 2 others like this

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

.

 

eMyvnE








#2 onlee

onlee

    Seeker

  • Active Members
  • 15 posts

Posted 09 November 2008 - 10:43 PM

nice script thanks :mellow:
($by_keven) ? ("http://wolfsecurity.org")

#3 mikeytown2

mikeytown2

    Polymath

  • Active Members
  • PipPipPipPip
  • 211 posts

Posted 10 November 2008 - 12:40 AM

Good to hear I inspired you! Would you mind giving an example? Like sending a POST with these parameters
user=admin
pass=admin
post data: restart=Restart?
http://www.autoitscript.com/forum/index.php?showtopic=83971
Or does WinHTTP still need some work in order to accomplish this?

#4 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 10 November 2008 - 01:25 AM

Good to hear I inspired you! Would you mind giving an example? Like sending a POST with these parameters
user=admin
pass=admin
post data: restart=Restart?
http://www.autoitscript.com/forum/index.php?showtopic=83971
Or does WinHTTP still need some work in order to accomplish this?

Try this:
AutoIt         
 #include "WinHTTP.au3" $LocalIP = "192.168.3.1" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP) $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "restart.cgi") _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, "admin", "admin") _WinHttpSendRequest($h_openRequest) _WinHttpWriteData($h_openRequest, "restart=Restart?") _WinHttpReceiveResponse($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, _             "ptr", 0)         If @error Or Not $a_iCall[0] Then         Return SetError(1, 0, -1)     EndIf     Return SetError(0, 0, $a_iCall[0])         EndFunc   ;==>_WinHttpWriteData


That script have _WinHttpWriteData() that is not in WinHTTP.au3 (I wasn't sure about "str" or "wstr" in dll call).

Edited by trancexx, 10 November 2008 - 09:58 AM.

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

.

 

eMyvnE


#5 Robjong

Robjong

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 318 posts

Posted 10 November 2008 - 03:14 PM

looks good, will test it a bit later on, thanks for sharing :mellow:


Robjong

#6 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 10 November 2008 - 03:51 PM

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

Edited by ProgAndy, 10 November 2008 - 04:08 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

#7 mikeytown2

mikeytown2

    Polymath

  • Active Members
  • PipPipPipPip
  • 211 posts

Posted 10 November 2008 - 07:14 PM

I think a wrapper for these functions would be helpful... here's my untested take on it

AutoIt         
Func WinHttpWrapper($URL, $Type, $Data = "", $username = "", $password = "", $protocall = "HTTP/1.1")     $temp = SplitURL($URL)     $Server = $temp[0]     $Address = $temp[1]     $hw_open = _WinHttpOpen("WinHTTP Example")     $hw_connect = _WinHttpConnect($hw_open, $Server)     $h_openRequest = _WinHttpOpenRequest($hw_connect, $Type, $Address, $protocall)     _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $username, $password)     _WinHttpSendRequest($h_openRequest)     _WinHttpWriteData($h_openRequest, $Data)     $Response = _WinHttpReceiveResponse($h_openRequest)     _WinHttpCloseHandle($h_openRequest)     _WinHttpCloseHandle($hw_connect)     _WinHttpCloseHandle($hw_open)     Return $Response EndFunc Func SplitURL($URL)     Dim $array[2]     $split = SplitURLHelper($URL, 3)     If $split == 0 Then         $split = SplitURLHelper($URL, 2)         $URL = StringRight($URL, $split)         $array[0] = $URL         Return $array     EndIf         $left = StringLeft($URL, $split)     $right = StringRight($URL, $split)         $split = SplitURLHelper($left, 2)     $left = StringRight($left, $split)         $array[0] = $left     $array[1] = $right     Return $array EndFunc Func SplitURLHelper($String, $pos)     $split = StringInStr($String, "/", 0, $pos)     If $split == 0 Then         $split = StringInStr($String, "\", 0, $pos)     EndIf     Return $split EndFunc


#8 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 11 November 2008 - 05:37 PM

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

Yes, ok.
"ptr" to "dword*"?
That parameter is set to 0.

I have made a modification or two to _WinHttpSendRequest() to meat* another (original actually) way of sending aditional data to the sever.
New (modified) _WinHttpSendRequest():
AutoIt         
; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpSendRequest ; Description ...: Sends the specified request to the HTTP server. ; Syntax.........: _WinHttpSendRequest($hRequest [, $pwszHeaders [, $sOptional [, $dwTotalLength [, $dwContext]]]]) ; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest(). ; $pwszHeaders - String that contains the additional headers to append to the request. Default is $WINHTTP_NO_ADDITIONAL_HEADERS. ; $sOptional - String that contains any optional data to send immediately after the request headers. Default is $WINHTTP_NO_REQUEST_DATA. ; $dwTotalLength - An unsigned long integer value that contains the length, in bytes, of the total optional data sent. Default is 0. ; $dwContext - A pointer to a pointer-sized variable that contains an application-defined value that is passed, with the request handle, to any callback functions. Default is 0. ; Return values .: Success - Returns 1. ; - Sets @error to 0 ; Failure - Returns -1 and sets @error: ; |1 - DllCall failed. ; Author ........: trancexx ; Modified.......: ; Remarks .......: Specifying optional data ($sOptional) will cause $dwTotalLength to receive the size of that data if left default value. ; Related .......: ; Link ..........; <a href='http://msdn.microsoft.com/en-us/library/aa384110(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/aa384110(VS.85</a>).aspx ; Example .......; Yes ; ;========================================================================================== Func _WinHttpSendRequest($hRequest, $pwszHeaders = $WINHTTP_NO_ADDITIONAL_HEADERS, $sOptional = $WINHTTP_NO_REQUEST_DATA, $dwTotalLength = 0, $dwContext = 0)     Local $iOptionalLength = StringLen($sOptional)     Local $structOptional = DllStructCreate("char[" & $iOptionalLength + 1 & "]")     DllStructSetData($structOptional, 1, $sOptional)     If Not $dwTotalLength Or $dwTotalLength < $iOptionalLength Then         $dwTotalLength += $iOptionalLength     EndIf         Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpSendRequest", _             "hwnd", $hRequest, _             "wstr", $pwszHeaders, _             "dword", 0, _             "ptr", DllStructGetPtr($structOptional), _             "dword", $iOptionalLength, _             "dword", $dwTotalLength, _             "ptr", $dwContext)     If @error Or Not $a_iCall[0] Then         SetError(1, 0, 0)     EndIf         Return SetError(0, 0, 1) EndFunc ;==>_WinHttpSendRequestƒ


@mikeytown2; I can see how can (could) that be useful.


edit: meat* = meet

Edited by Jon, 03 November 2012 - 05:03 PM.

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

.

 

eMyvnE


#9 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 11 November 2008 - 07:14 PM

I'm having problems with this six functions:
No5. WinHttpCrackUrl
No6. WinHttpCreateUrl
...l
No23. WinHttpSetStatusCallback
No27. WinHttpWriteData


WinHttpWriteData has been translated by trancexx and me.
Now, i#ll post WinHttpCrackUrl, WinHttpCreateUrl and WinHttpSetStatusCallback :mellow:
(examples in the files)

Attached Files


Edited by ProgAndy, 11 November 2008 - 07:14 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

#10 JRSmile

JRSmile

    IT infrastructure specialist

  • Active Members
  • PipPipPipPipPipPip
  • 455 posts

Posted 12 November 2008 - 11:11 AM

i played a bit with it but could not figure out how to send cookies correctly, any idea?

EDIT:
saw that it handeles cookies automatically GREAT...

now i just have to figure out why i still can't login ....

EDIT2: HEEEEEELLLLLPPPPPPPP

tried everything even fighting through msdn KB but can't figure out how to send a simple post request with a pin=123456 attribut, so that it will allow me to logon :mellow:
with the old winhttp udf powered by tcp open .... it was solved as this:
_HTTPPost('', $sessionid2, '', $fax_device & ":8000", '/login', $socket, 'pin=98765&uri=%2Frps%2F_top.htm')

any nice help appreciated :-)

Edited by JRSmile, 12 November 2008 - 12:43 PM.

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));)''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)Try2Hack: http://www.try2hack.nl/levels/level13-olwehfdow.xhtml

#11 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 12 November 2008 - 08:21 PM

WinHttpWriteData has been translated by trancexx and me.
Now, i#ll post WinHttpCrackUrl, WinHttpCreateUrl and WinHttpSetStatusCallback :mellow:
(examples in the files)

Now that's what I'm talking about!
Will add that functions to first post attachments (after I modify them just a bit, hope you wouldn't mind - style differences)

edit:
I like the way you sized the structures in _WinHttpCrackUrl() and stripped output afterwards

Edited by trancexx, 12 November 2008 - 08:25 PM.

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

.

 

eMyvnE


#12 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 12 November 2008 - 09:44 PM

This may come in handy as I've been trying to do HTTP functions (file download) with this UDF WinINet.au3 (FTP/HTTP/HTTPS/Gopher+)

Now, I'm wondering what your thoughts about using WinInet over WinHTTP, WinINet seems more robust as it also includes functions for FTP, HTTPS, and Gopher+. Your UDF; WinHTTP is more tailored for HTTP. I want to know, does it contain more functions for HTTP? Is it faster, what's the reason for reinventing the wheel?

Microsoft insist on making development an arms length in becoming dependent on Tylenol pills. :mellow:

Edited by mrRevoked, 12 November 2008 - 09:45 PM.

Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#13 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 13 November 2008 - 03:09 PM

Now that's what I'm talking about!
Will add that functions to first post attachments (after I modify them just a bit, hope you wouldn't mind - style differences)

edit:
I like the way you sized the structures in _WinHttpCrackUrl() and stripped output afterwards

You can modify them as much as you want :mellow: I just wanted to create examples, so the code isn't written perfectly... You should also create documentaion for the funcs.
*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

#14 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 13 November 2008 - 07:41 PM

This may come in handy as I've been trying to do HTTP functions (file download) with this UDF WinINet.au3 (FTP/HTTP/HTTPS/Gopher+)

Now, I'm wondering what your thoughts about using WinInet over WinHTTP, WinINet seems more robust as it also includes functions for FTP, HTTPS, and Gopher+. Your UDF; WinHTTP is more tailored for HTTP. I want to know, does it contain more functions for HTTP? Is it faster, what's the reason for reinventing the wheel?

Microsoft insist on making development an arms length in becoming dependent on Tylenol pills. :mellow:

castoff?

Advantages or disadvantages of this or that are yet to be determined.
This is not reinventing the wheel, but offering another option. Something like this:
Beep(400, 200) DllCall("msvcrt.dll", "int:cdecl", "_beep", "int", 500, "int", 200) DllCall("kernel32.dll","int", "Beep","int",600,"int",200) DllCall("pncrt.dll", "int:cdecl", "_beep", "int", 700, "int", 200)


First post updated.

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

.

 

eMyvnE


#15 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 13 November 2008 - 08:12 PM

i played a bit with it but could not figure out how to send cookies correctly, any idea?

EDIT:
saw that it handeles cookies automatically GREAT...

now i just have to figure out why i still can't login ....

EDIT2: HEEEEEELLLLLPPPPPPPP

tried everything even fighting through msdn KB but can't figure out how to send a simple post request with a pin=123456 attribut, so that it will allow me to logon :mellow:
with the old winhttp udf powered by tcp open .... it was solved as this:
_HTTPPost('', $sessionid2, '', $fax_device & ":8000", '/login', $socket, 'pin=98765&uri=%2Frps%2F_top.htm')

any nice help appreciated :-)

Just post script with calling _HTTPPost() properly and we'll find the solution, I'm sure.

Few examples using WinHTTP.au3 functions.
AutoIt         
#include "WinHTTP.au3" #include <Array.au3> ;Checking platform: If _WinHttpCheckPlatform() Then     MsgBox(0, "WinHTTP checking platform result", "Platform supported") Else     MsgBox(0, "WinHTTP checking platform result", "Platform not supported!") EndIf ; Date and time according to the HTTP version 1.0 specification: MsgBox(0, "Date and time according to the HTTP version 1.0 specification", _WinHttpTimeFromSystemTime()) ; Transforming HTTP/1.0 time format to sistem time format: $time_array = _WinHttpTimeToSystemTime("Fri, 07 Nov 2010 20:42:16 GMT") _ArrayDisplay($time_array, "_WinHttpTimeToSystemTime()") ; Cracking URL: $URL_array = _WinHttpCrackUrl("<a href='http://www.autoitscript.com/forum/index.php?showforum=9' class='bbc_url' title=''>http://www.autoitscript.com/forum/index.php?showforum=9"</a>) _ArrayDisplay($URL_array, "_WinHttpCrackUrl()") ; Creating URL out of array of components: Global $URL_array[8] = ["http", 1, "www.autoitscript.com", 80, "Jon", "deadPiXels", "admin.php"] MsgBox(0, "Created URL", _WinHttpCreateUrl($URL_array))

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

.

 

eMyvnE


#16 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 15 November 2008 - 03:34 PM

Found some problems, if using String as Datatype for ReadData. This does not work, if HTML is in UTF-8 :mellow:
So i made some funcs using byte Structures, which you can convert with BinaryToString. Create Binary with StringToBinary;)
AutoIt         
; Prog@ndy ; reads complete HTML response in ASCII and UTF-8 encoding. Func _WinHttpReadHTML($hRequest)     Local $data     While 1         $chunk = _WinHttpReadDataBin($hRequest)         If @error <> 0 Then ExitLoop         $data = _BinaryConcat($data, $chunk)     WEnd     $Content_Type = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_TYPE)     Select         Case StringInStr($Content_Type, "charset=UTF-8")             $data = BinaryToString($data, 4)         Case Else             $data = BinaryToString($data)     EndSelect     Return $data EndFunc   ;==>_WinHttpReadHTML ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpSendRequestBin ; Description ...: Sends the specified request to the HTTP server. ; Syntax.........: _WinHttpSendRequest($hRequest [, $sHeaders [, $sOptional [, $iTotalLength [, $iContext]]]]) ; Parameters ....: $hRequest - Handle returned by _WinHttpOpenRequest(). ;                  $sHeaders - String that contains the additional headers to append to the request. Default is $WINHTTP_NO_ADDITIONAL_HEADERS. ;                  $sOptional - Binary Data that contains any optional data to send immediately after the request headers. Default is $WINHTTP_NO_REQUEST_DATA. ;                  $iTotalLength - An unsigned long integer value that contains the length, in bytes, of the total optional data sent. Default is 0. ;                  $iContext - A pointer to a pointer-sized variable that contains an application-defined value that is passed, with the request handle, to any callback functions. Default is 0. ; Return values .: Success - Returns 1. ;                          - Sets @error to 0 ;                  Failure - Returns -1 and sets @error: ;                  |1 - DllCall failed. ; Author ........: trancexx ; Modified.......: ; Remarks .......: Specifying optional data ($sOptional) will cause $iTotalLength to receive the size of that data if left default value. ; Related .......: ; Link ..........; <a href='http://msdn.microsoft.com/en-us/library/aa384110(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/aa384110(VS.85</a>).aspx ; Example .......; Yes ; ;========================================================================================== Func _WinHttpSendRequestBin($hRequest, $sHeaders = $WINHTTP_NO_ADDITIONAL_HEADERS, $sOptional = $WINHTTP_NO_REQUEST_DATA, $iTotalLength = 0, $iContext = 0)     Local $iOptionalLength = BinaryLen($sOptional)     Local $structOptional = DllStructCreate("byte[" & $iOptionalLength & "]")     DllStructSetData($structOptional, 1, $sOptional)     If Not $iTotalLength Or $iTotalLength < $iOptionalLength Then         $iTotalLength += $iOptionalLength     EndIf         Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpSendRequest", _             "hwnd", $hRequest, _             "wstr", $sHeaders, _             "dword", 0, _             "ptr", DllStructGetPtr($structOptional), _             "dword", $iOptionalLength, _             "dword", $iTotalLength, _             "ptr", $iContext)     If @error Or Not $a_iCall[0] Then         SetError(1, 0, 0)     EndIf         Return SetError(0, 0, 1) EndFunc   ;==>_WinHttpSendRequestBin ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpWriteDataBin ; Description ...: Writes request data to an HTTP server. ; Syntax.........: _WinHttpWriteData($hRequest, $string) ; Parameters ....: $hRequest - Valid handle returned by _WinHttpSendRequest(). ;                  $binary - Binary data to write. ; Return values .: Success - Returns 1 ;                          - Sets @error to 0 ;                          - sets @extended to written bytes ;                  Failure - Returns 0 and sets @error: ;                  |1 - DllCall failed. ; Author ........: trancexx, ProgAndy ; Modified.......: ; Remarks .......: ; 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 _WinHttpWriteDataBin($hRequest, $binary)     Local $lpBinary     Local $iNumberOfBytesToWrite     If IsDllStruct($binary) Then         $lpBinary = DllStructGetPtr($binary)         $iNumberOfBytesToWrite = DllStructGetSize($binary)     Else         $iNumberOfBytesToWrite = BinaryLen($binary)         Local $sBinary = DllStructCreate("byte[" & $iNumberOfBytesToWrite & "]")         DllStructSetData($sBinary, 1, $binary)         $lpBinary = DllStructGetPtr($binary)     EndIf         Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpWriteData", _             "hwnd", $hRequest, _             "ptr", $lpBinary, _             "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   ;==>_WinHttpWriteDataBin ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpReadDataBin ; Description ...: Reads data from a handle opened by the _WinHttpOpenRequest() function. ; Syntax.........: _WinHttpReadData($hRequest [, $iNumberOfBytesToRead]) ; Parameters ....: $hRequest - Valid handle returned from a previous call to _WinHttpOpenRequest(). ;                  $iNumberOfBytesToRead - Integer value that contains the number of bytes to read. Default is 8192 bytes. ; Return values .: Success - Returns data read. ;                          - Sets @error to 0 ;                  Failure - Returns empty string and sets @error: ;                  |1 - DllCall failed. ; Author ........: trancexx ; Modified.......: ; Remarks .......: ; 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 _WinHttpReadDataBin($hRequest, $iNumberOfBytesToRead = 8192)     Local $lpBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")     Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpReadData", _             "hwnd", $hRequest, _             "ptr", DllStructGetPtr($lpBuffer), _             "ulong", $iNumberOfBytesToRead, _             "dword*", 0)     Select         Case @error Or Not $a_iCall[0]             Return SetError(1)         Case $a_iCall[4] = 0             Return SetError(-1)         Case $a_iCall[4] < $iNumberOfBytesToRead             Return BinaryMid(DllStructGetData($lpBuffer, 1), 1, $a_iCall[4])     EndSelect         Return DllStructGetData($lpBuffer, 1)     EndFunc   ;==>_WinHttpReadDataBin ;=============================================================================== ; ; Function Name:   _BinaryConcat ; Description::    Concatenates 2 binary Variables ; Parameter(s):    2 Binary variables, by reference ; Requirement(s): ; Return Value(s): New Binary data ; Author(s):       Prog@ndy ; ;=============================================================================== ; Func _BinaryConcat(ByRef $Binary1, ByRef $Binary2)     Select         Case IsBinary($Binary1) And Not IsBinary($Binary2)             Return $Binary1         Case Not IsBinary($Binary1) And IsBinary($Binary2)             Return $Binary2         Case Not (IsBinary($Binary1) And IsBinary($Binary2))             Return SetError(1)     EndSelect     Local $Len1 = BinaryLen($Binary1), $Len2 = BinaryLen($Binary2)     Local $s = DllStructCreate("byte[" & $Len1 & "];byte[" & $Len2 & "]")     DllStructSetData($s, 1, $Binary1)     DllStructSetData($s, 2, $Binary2)     Return DllStructGetData(DllStructCreate("byte[" & $Len1 + $Len2 & "]", DllStructGetPtr($s)), 1) EndFunc   ;==>_BinaryConcat

Edited by ProgAndy, 15 November 2008 - 03:34 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

#17 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 15 November 2008 - 07:18 PM

I wasn't experiencing that difficulties, and was aiming sites with different charsets deliberately.

Will test that.

I was pretty sure that I changed the last parameter of DllCall() in _WinHttpReadData() from "ptr" to "dword*" and throw it out as @extended.

This is not working for you?
AutoIt         
#include "WinHTTP.au3" Global $hw_open = _WinHttpOpen("WinHTTP Example") If @error Then     MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")     Exit EndIf Global $hw_connect = _WinHttpConnect($hw_open, "msdn.microsoft.com") If @error Then     MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")     _WinHttpCloseHandle($hw_open)     Exit EndIf Global $h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "en-us/library/aa384104(VS.85).aspx") If @error Then     MsgBox(48, "Error", "Error creating an HTTP request handle.")     _WinHttpCloseHandle($hw_connect)     _WinHttpCloseHandle($hw_open)     Exit EndIf _WinHttpSendRequest($h_openRequest) If @error Then     MsgBox(48, "Error", "Error sending the specified request.")     _WinHttpCloseHandle($hw_connect)     _WinHttpCloseHandle($hw_open)     Exit EndIf _WinHttpReceiveResponse($h_openRequest) If _WinHttpQueryDataAvailable($h_openRequest) Then     Global $header = _WinHttpQueryHeaders($h_openRequest)     ConsoleWrite($header & @CRLF & @CRLF)     Global $data     While 1         $data &= X_WinHttpReadData($h_openRequest)         If Not @extended Then ExitLoop          WEnd     ConsoleWrite($data & @CRLF) EndIf _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) Func X_WinHttpReadData($hRequest, $iNumberOfBytesToRead = 8192)     Local $lpBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")     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         Return SetError(0, $a_iCall[4], DllStructGetData($lpBuffer, 1))     EndFunc

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

.

 

eMyvnE


#18 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 16 November 2008 - 10:50 AM

No. try on Autoit.de:
1) recieving Vorgänge instead of Vorgänge
2) have additional data at the end:
</html> 0 .

second problem can be fixed this way:
AutoIt         
Func X_WinHttpReadData($hRequest, $iNumberOfBytesToRead = 8192)     Local $lpBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")     Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpReadData", _             "hwnd", $hRequest, _             "ptr", DllStructGetPtr($lpBuffer), _             "ulong", $iNumberOfBytesToRead, _             "dword*", 0)         Select         Case @error Or Not $a_iCall[0]             Return SetError(1, 0, "")         Case Not $a_iCall[4]             Return SetError(0, 0, "")         Case $a_iCall[4] < $iNumberOfBytesToRead             Return SetError(0, $a_iCall[4], StringLeft(DllStructGetData($lpBuffer, 1),$a_iCall[4]))     EndSelect         Return SetError(0, $a_iCall[4], DllStructGetData($lpBuffer, 1))     EndFunc

I propose to create two functions. One with char and another with Binary :mellow: So everyone can decide what he needs (e.g. if you want to download (upload) files, Binary is useful, too.)

Edited by ProgAndy, 16 November 2008 - 10:53 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

#19 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 5,989 posts

Posted 16 November 2008 - 03:44 PM

This is great! I think that we'll make something out of this :mellow:

About two functions...
Maybe just one, like this:

AutoIt         
#include "WinHTTP.au3" Global $hw_open = _WinHttpOpen() If @error Then     MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")     Exit EndIf Global $hw_connect = _WinHttpConnect($hw_open, "www.autoit.de") If @error Then     MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")     _WinHttpCloseHandle($hw_open)     Exit EndIf Global $h_openRequest = _WinHttpOpenRequest($hw_connect) If @error Then     MsgBox(48, "Error", "Error creating an HTTP request handle.")     _WinHttpCloseHandle($hw_connect)     _WinHttpCloseHandle($hw_open)     Exit EndIf _WinHttpSendRequest($h_openRequest) If @error Then     MsgBox(48, "Error", "Error sending the specified request.")     _WinHttpCloseHandle($hw_connect)     _WinHttpCloseHandle($hw_open)     Exit EndIf _WinHttpReceiveResponse($h_openRequest) If _WinHttpQueryDataAvailable($h_openRequest) Then     Global $header = _WinHttpQueryHeaders($h_openRequest)     ConsoleWrite($header & @CRLF & @CRLF)     Global $chunk, $data, $extended     While 1         $chunk = X_WinHttpReadData($h_openRequest, 2)         If Not @extended Then ExitLoop         $data = _WinHttpBinaryConcat($data, $chunk)         WEnd     ConsoleWrite(BinaryToString($data, 4) & @CRLF) Else     MsgBox(48, "Error", "Site is experiencing problems.") EndIf _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) ; #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 taken to be ANSI related). ;                  $iNumberOfBytesToRead - Integer value that contains the number of bytes to read. Default is 8192 bytes. ; Return values .: Success - Returns data read. ;                          - Sets @error to 0 ;                  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 X_WinHttpReadData($hRequest, $iMode = 0, $iNumberOfBytesToRead = 8192)     Local $lpBuffer         Switch $iMode         Case 0             $lpBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")         Case 1, 2             $lpBuffer = DllStructCreate("byte[" & $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 $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 EndFunc   ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WinHttpBinaryConcat ; Description ...: Concatenates two binary data returned by _WinHttpReadData() in binary mode. ; Syntax.........: _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2) ; Parameters ....: $bBinary1 - Binary data that is to be concatenated. ;                  $bBinary2 - Binary data to concat. ; Return values .: Success - Returns concatenated binary data. ;                          - Sets @error to 0 ;                  Failure - Returns 0 and sets @error: ;                  |1 - Invalid input. ; Author ........: ProgAndy ; Modified.......: trancexx ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; ;========================================================================================== Func _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)             Switch IsBinary($bBinary1) & IsBinary($bBinary2)         Case 0             Return SetError(1, 0, 0)         Case 1             Return SetError(0, 0, $bBinary2)         Case 10             Return SetError(0, 0, $bBinary1)     EndSwitch                   Local $iLen1 = BinaryLen($bBinary1)     Local $iLen2 = BinaryLen($bBinary2)         Local $struct = DllStructCreate("byte[" & $iLen1 & "];byte[" & $iLen2 & "]")     DllStructSetData($struct, 1, $bBinary1)     DllStructSetData($struct, 2, $bBinary2)         Return DllStructGetData(DllStructCreate("byte[" & $iLen1 + $iLen2 & "]", DllStructGetPtr($struct)), 1)     EndFunc   ;==>_WinHttpBinaryConcatƒo݊÷ Ù8Z¶+(¥é➠aŠÊh²È›ŠX­É«­¢+؍¥¹±Õ‘”€™ÅÕ½Ðí]¥¹!QQ@¹…Ô̙ÅÕ½Ðì(()±½‰…°€˜ŒÀÌØí¡Ý}½Á•¸€ô}]¥¹!ÑÑÁ=Á•¸ ¤)%˜•ÉɽȁQ¡•¸(%5͝ ½à Ðఀ™ÅÕ½ÐíÉɽșÅÕ½Ð찀™ÅÕ½ÐíÉɽȁ¥¹¥Ñ¥…±¥é¥¹œÑ¡”Õͅ”½˜]¥¹!QQ@™Õ¹Ñ¥½¹Ì¸™ÅÕ½Ðì¤(%á¥Ð)¹‘%˜()±½‰…°€˜ŒÀÌØí¡Ý}½¹¹•Ð€ô}]¥¹!ÑÑÁ ½¹¹•Ð ˜ŒÀÌØí¡Ý}½Á•¸°€™ÅÕ½ÐíÝÝܹ…Õѽ¥Ð¹‘”™ÅÕ½Ðì¤)%˜•ÉɽȁQ¡•¸(%5͝ ½à Ðఀ™ÅÕ½ÐíÉɽșÅÕ½Ð찀™ÅÕ½ÐíÉɽȁÍÁ•¥™å¥¹œÑ¡”¥¹¥Ñ¥…°Ñ…ɝ•ÐÍ•Éٕȁ½˜…¸!QQ@É•ÅՕÍи™ÅÕ½Ðì¤(%}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½Á•¸¤(%á¥Ð)¹‘%˜()±½‰…°€˜ŒÀÌØí¡}½Á•¹I•ÅՕÍЀô}]¥¹!ÑÑÁ=Á•¹I•ÅՕÍÐ ˜ŒÀÌØí¡Ý}½¹¹•Ð¤)%˜•ÉɽȁQ¡•¸(%5͝  ½à Ðఀ™ÅÕ½ÐíÉɽșÅÕ½Ð찀™ÅÕ½ÐíÉɽȁÉ•…Ñ¥¹œ…¸!QQ@É•ÅՕÍЁ¡…¹‘±”¸™ÅÕ½Ðì¤(%}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½¹¹•Ð¤(%}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½Á•¸¤(%á¥Ð)¹‘%˜()}]¥¹!ÑÑÁM•¹‘I•ÅՕÍÐ ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍФ)%˜•ÉɽȁQ¡•¸(%5͝    ½à Ðఀ™ÅÕ½ÐíÉɽșÅÕ½Ð찀™ÅÕ½ÐíÉɽȁ͕¹‘¥¹œÑ¡”ÍÁ•¥™¥•É•ÅՕÍи™ÅÕ½Ðì¤(%}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½¹¹•Ð¤(%}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½Á•¸¤(%á¥Ð)¹‘%˜()}]¥¹!ÑÑÁI••¥Ù•I•ÍÁ½¹Í” ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍФ()%˜}]¥¹!ÑÑÁEՕÉå…Ñ…م¥±…‰±” ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍФQ¡•¸(%±½‰…°€˜ŒÀÌØí¡•…‘•È€ô}]¥¹!ÑÑÁEՕÉå!•…‘•ÉÌ ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍФ(% ½¹Í½±•]ɥє ˜ŒÀÌØí¡•…‘•È€™…µÀì I1€™…µÀì I1¤(%±½‰…°€˜ŒÀÌØ퍡չ¬°€˜ŒÀÌØ푅ф°€˜ŒÀÌØí•áѕ¹‘•(%]¡¥±”€Ä($$˜ŒÀÌØ퍡չ¬€ôa}]¥¹!ÑÑÁI•…‘…Ñ„ ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍа€Ä¤($%%˜9½Ð•áѕ¹‘•Q¡•¸á¥Ñ1½½À($$˜ŒÀÌØ푅ф€™…µÀìô€˜ŒÀÌØ퍡չ¬$(%]¹(% ½¹Í½±•]ɥє ˜ŒÀÌØ푅ф€™…µÀì I1¤)±Í”(%5͝    ½à Ðఀ™ÅÕ½ÐíÉɽșÅÕ½Ð찀™ÅÕ½ÐíM¥Ñ”¥Ì•áÁ•É¥•¹¥¹œÁɽ‰±•µÌ¸™ÅÕ½Ðì¤)¹‘%˜()}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡}½Á•¹I•ÅՕÍФ)}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½¹¹•Ð¤)}]¥¹!ÑÑÁ ±½Í•!…¹‘±” ˜ŒÀÌØí¡Ý}½Á•¸¤(((쀍U9 Q%=8Œ€ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ì(ì9…µ”¸¸¸¸¸¸¸¸¸¸¸è}]¥¹!ÑÑÁI•…‘…Ñ„(쁕͍ɥÁÑ¥½¸€¸¸¸èI•…‘́‘…Ñ„™É½´„¡…¹‘±”½Á•¹•‰äÑ¡”}]¥¹!ÑÑÁ=Á•¹I•ÅՕÍÐ ¤™Õ¹Ñ¥½¸¸(ìMå¹Ñ…ุ¸¸¸¸¸¸¸è}]¥¹!ÑÑÁI•…‘…Ñ„ ˜ŒÀÌØí¡I•ÅՕÍЁl°¥5½‘”l°€˜ŒÀÌØí¥9Õµ‰•É=™ åѕÍQ½I•…‘ut¤(ìA…É…µ•Ñ•É̀¸¸¸¸è€˜ŒÀÌØí¡I•ÅՕÍЀ´Y…±¥¡…¹‘±”É•ÑÕɹ•™É½´„Áɕ٥½Ṍ…±°Ñ¼}]¥¹!ÑÑÁ=Á•¹I•ÅՕÍÐ ¤¸(쀀€€€€€€€€€€€€€€€€˜ŒÀÌØí¥5½‘”€´%¹Ñ••ÈÉ•Áɕ͕¹Ñ¥¹œÉ•…‘¥¹œµ½‘”¸•™…ձЁ¥Ì€À€¡¡…É͕Ё¥ÌÑ…­•¸Ñ¼‰”9M$É•±…Ñ•¤¸(쀀€€€€€€€€€€€€€€€€˜ŒÀÌØí¥9Õµ‰•É=™   åѕÍQ½I•…€´%¹Ñ••ÈÙ…±Õ”Ñ¡…Ё½¹Ñ…¥¹ÌÑ¡”¹Õµ‰•È½˜‰åѕ́ѼÉ•…¸•™…ձЁ¥Ì€àÄäȁ‰åѕ̸(ìI•ÑÕɸÙ…±Õ•Ì€¸èMՍ•Í̀´I•ÑÕɹ́‘…Ñ„É•…¸(쀀€€€€€€€€€€€€€€€€€€€€€€€€´M•Ñ́•ÉɽȁѼ€À(쀀€€€€€€€€€€€€€€€…¥±Õɔ€´I•ÑÕɹ́•µÁÑäÍÑÉ¥¹œ…¹Í•Ñ́•ÉɽÈè(쀀€€€€€€€€€€€€€€€ðĀ´±± …±°™…¥±•¸(ìÕÑ¡½È€¸¸¸¸¸¸¸¸èÑɅ¹•áఁAɽ¹‘ä(ì5½‘¥™¥•¸¸¸¸¸¸¸è(ìI•µ…É­Ì€¸¸¸¸¸¸¸è¥5½‘”…¸¡…Ù”Ñ¡•Í”Ù…±Õ•Ìè(쀀€€€€€€€€€€€€€€€ðÀ€´9M$€(쀀€€€€€€€€€€€€€€€ðĀ´UQà(쀀€€€€€€€€€€€€€€€ðȀ´   ¥¹…Éä(ìI•±…Ñ•€¸¸¸¸¸¸¸è(ì1¥¹¬€¸¸¸¸¸¸¸¸¸¸ì¡ÑÑÀè¼½µÍ‘¸¹µ¥É½Í½™Ð¹½´½•¸µÕ̽±¥‰É…É佅„ÌàÐÄÀСYL¸àÔ¤¹…ÍÁà(ìᅵÁ±”€¸¸¸¸¸¸¸ìe•Ì(ì(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹Œa}]¥¹!ÑÑÁI•…‘…Ñ„ ˜ŒÀÌØí¡I•ÅՕÍа€˜ŒÀÌØí¥5½‘”€ô€À°€˜ŒÀÌØí¥9Õµ‰•É=™  åѕÍQ½I•…€ô€àÄäȤ€((%1½…°€˜ŒÀÌØí±Á  ՙ™•È($(%Mݥэ €˜ŒÀÌØí¥5½‘”($% …Í”€À($$$˜ŒÀÌØí±Á  ՙ™•È€ô±±MÑÉÕÑ É•…Ñ” ™ÅÕ½Ð퍡…Él™ÅÕ½Ð쀙…µÀ쀘ŒÀÌØí¥9Õµ‰•É=™  åѕÍQ½I•…€™…µÀ쀙ÅÕ½Ðít™ÅÕ½Ðì¤($% …Í”€Ä°€È($$$˜ŒÀÌØí±Á    ՙ™•È€ô±±MÑÉÕÑ É•…Ñ” ™ÅÕ½Ðí‰åѕl™ÅÕ½Ð쀙…µÀ쀘ŒÀÌØí¥9Õµ‰•É=™  åѕÍQ½I•…€™…µÀ쀙ÅÕ½Ðít™ÅÕ½Ðì¤(%¹‘Mݥэ ($(%1½…°€˜ŒÀÌØí…}¥ …±°€ô±± …±° ™ÅÕ½Ðí]¥¹¡ÑÑÀ¹‘±°™ÅÕ½Ð찀™ÅÕ½Ðí¥¹Ð™ÅÕ½Ð찀™ÅÕ½Ðí]¥¹!ÑÑÁI•…‘…Ñ„™ÅÕ½Ð찁|($$$™ÅÕ½Ðí¡Ý¹™ÅÕ½Ð찀˜ŒÀÌØí¡I•ÅՕÍа|($$$™ÅÕ½ÐíÁÑșÅÕ½Ð찁±±MÑÉՍÑ•ÑAÑÈ ˜ŒÀÌØí±Á  ՙ™•È¤°|($$$™ÅÕ½ÐíÕ±½¹œ™ÅÕ½Ð찀˜ŒÀÌØí¥9Õµ‰•É=™ åѕÍQ½I•…°|($$$™ÅÕ½Ðí‘ݽɐ¨™ÅÕ½Ð찀À¤((%%˜•Éɽȁ=ȁ9½Ð€˜ŒÀÌØí…}¥ …±±lÁtQ¡•¸($%M•ÑÉÉ½È Ä°€À°€™ÅÕ½Ðì™ÅÕ½Ðì¤(%¹‘%˜((%Mݥэ €˜ŒÀÌØí¥5½‘”($% …Í”€À($$%I•ÑÕɸM•ÑÉÉ½È À°€˜ŒÀÌØí…}¥ …±±lÑt°MÑÉ¥¹1•™Ð¡±±MÑÉՍÑ•Ñ…Ñ„ ˜ŒÀÌØí±Á ՙ™•È°€Ä¤°€˜ŒÀÌØí…}¥ …±±lÑt¤¤($% …Í”€Ä($$%I•ÑÕɸM•ÑÉÉ½È À°€˜ŒÀÌØí…}¥ …±±lÑt°  ¥¹…ÉåQ½MÑÉ¥¹œ¡  ¥¹…Éå5¥¡±±MÑÉՍÑ•Ñ…Ñ„ ˜ŒÀÌØí±Á  ՙ™•È°€Ä¤°€Ä°€˜ŒÀÌØí…}¥ …±±lÑt¤°€Ð¤¤($% …Í”€È($$%I•ÑÕɸM•ÑÉÉ½È À°€˜ŒÀÌØí…}¥ …±±lÑt°  ¥¹…Éå5¥¡±±MÑÉՍÑ•Ñ…Ñ„ ˜ŒÀÌØí±Á  ՙ™•È°€Ä¤°€Ä°€˜ŒÀÌØí…}¥ …±±lÑt¤¤(%¹‘Mݥэ ()¹‘Õ¹Œ

Prefix "X" is used not to colide with current _WinHttpReadData() function

Find flaw, if any.
Maybe to set UTF-8 as default?

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

.

 

eMyvnE


#20 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 17 November 2008 - 12:23 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

Edited by ProgAndy, 17 November 2008 - 12:23 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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users