Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

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:

end Source

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

Please help me soon!

You should try posting here. That's the forum specialized for that kind of stuff.

Really, try there. People there are more friendly and everything. Altruism rules there.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 2 months later...

Hello i'm frenche sorry for my english

I use your UDF to post a file on dl.free.fr. with success. and a _IECreateEmbedded().

But in the end of proccess, the server send me a webpage that containt an URL to delete the file and other. When i click on an URL it crashes.

exit code in Scite: !>14:50:03 AutoIT3.exe ended.rc:-1073741819

Some idea, problem with _IENaviagte() or UDF ???

#cs ----------------------------------------------------------------------------
     
         AutoIt Version : 3.3.0.0
         Auteur:         GaRy delaMer
     
         Fonction du Script : Exemple
         Un petit navigateur web intégrer dans une GUI
     
     #ce ----------------------------------------------------------------------------
     #Region;**** Directives created by AutoIt3Wrapper_GUI ****
     #AutoIt3Wrapper_Outfile=GaRy deleMer WebBrowser.Exe
     #AutoIt3Wrapper_Compression=4
     #Tidy_Parameters=/sf
     #EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
     #Region;**** Options AutoIt                           ****
     Opt('MustDeclareVars', 1)
     Opt('GUICloseOnESC', 1)
     #EndRegion;===============================================
     #Region;**** Include AutoIt                              ****
     #include <GUIConstantsEx.au3>
     #include <ProgressConstants.au3>
     #include <WindowsConstants.au3>
     #include <IE.au3>
     #include <INet.au3>
     #include <Misc.au3>
     #include <GuiStatusBar.au3>
     #include <ScreenCapture.au3>
     #EndRegion;===============================================
     
     Global $Titre_Appli = "GaRy delaMer FileUpload://"
     If Not @Compiled Then
         _Singleton($Titre_Appli)
         HotKeySet("!x", "_GUIEvent_Quit")
     EndIf
     
     #include <WinHTTPConstants.au3>
     #include <WinHTTP.au3>
     
     #Region;**** Gui, ActiveX _IE, statusbar              ****
     Global $hGUI = GUICreate($Titre_Appli, @DesktopWidth * 3 / 5, @DesktopHeight * 3 / 5, -1, -1, _
             $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
;; les menus
     Global $filemenu = GUICtrlCreateMenu("&Page")
     Global $urlitem = GUICtrlCreateMenuItem("&Aller à l'adresse", $filemenu)
     Global $fileitem = GUICtrlCreateMenuItem("&Ouvre un fichier", $filemenu)
     Global $htmlitem = GUICtrlCreateMenuItem("&Coller du code html", $filemenu)
     GUICtrlCreateMenuItem("", $filemenu)
     Global $exititem = GUICtrlCreateMenuItem("&Quitter", $filemenu)
;; Le contrôle ActivX IE
     _IEErrorHandlerRegister()
     Global $oIE = _IECreateEmbedded()
     Global $hIE = GUICtrlCreateObj($oIE, 22, 0)
; Assign events to UDFs starting with IEEvent_
     Global $LoadComplete = False
     Global $oIEEvent = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")
     
     Global $URL = "about:blank"
     _IENavigateComplete($URL)
     
     GUIRegisterMsg($WM_SIZE, "_My_WM_SIZE")
     GUISetState();Show GUI
     _GUIEVENT_Resize()
     #EndRegion;===============================================
     
     Global $testmenu = GUICtrlCreateMenu("&Test")
     Global $post_files = GUICtrlCreateMenuItem("&Poster un fichier chez Free.fr", $testmenu)
     
     While 1
         Local $msg = GUIGetMsg()
         Switch $msg
             Case $post_files
                 _Post_Files()
             Case $urlitem
                 Local $surl = InputBox("Entrer l'adresse", "Saisir l'adresse du site")
                 If $surl <> "" Then _IENavigate($oIE, $surl) 
             Case $fileitem
                 Local $hFile = FileOpenDialog("Ouvre une source HTML", @ScriptDir, _
                         "Source html (*.html; *.htm; *.txt)|Tous (*.*)", 11, "", WinGetHandle($hGUI))
                 If Not @error Then
                     Local $html = FileRead($hFile)
                     If $html <> "" Then
                         _IEBodyWriteHTML($oIE, $html)
                     EndIf
                 EndIf
             Case $htmlitem
                 Local $html = ClipGet()
                 If IsString($html) And $html <> "" Then _IEBodyWriteHTML($oIE, $html)
             Case $GUI_EVENT_CLOSE, $exititem
                 _GUIEvent_Quit()
         EndSwitch
     WEnd
     
     Func _Post_Files()
         Local $hOpen = _WinHttpOpen("AutoIt v3.3.0", $WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
         Local $URL = _WinHttpCrackUrl("http://dl.free.fr/index_nojs.pl")
         Local $Host = $URL[2]
         Local $Port = $URL[3]
         Local $Referrer = "http://" & $URL[2]
         Local $QueryString = $URL[6] & $URL[7]
         Local $hConnect = _WinHTTPConnect($hOpen, $Host, $Port)
     
    ;; Juste pour retrouver l'adresse pour faire le post, peu être caché
         Local $hRequest = _WinHttpOpenRequest($hConnect, "GET", $QueryString, "HTTP/1.1", $Referrer)
         _WinHttpSendRequest($hRequest)
         _WinHttpReceiveResponse($hRequest)
         Local $html[3] = ["", _WinHttpQueryHeaders($hRequest), _WinHttpQueryOption($hRequest, $WINHTTP_OPTION_URL)]
         If _WinHttpQueryDataAvailable($hRequest) Then
             Local $temp
             While 1
                 $temp = _WinHttpReadData($hRequest)
                 If $temp = "" Then ExitLoop
                 $html[0] &= $temp
             WEnd
             $temp = ""
         EndIf
         _WinHttpCloseHandle($hRequest)
         _Debug($html[1] & $html[2] & @LF)
         _IEDocWriteHTML($oIE, $html[0])
     
         _ScreenCapture_Capture(@TempDir & "\capture.jpg", 100, 100, 100, 100, False)
         Local $oForm = _IEFormGetCollection($oIE, 1)
         Local $URL = _WinHttpCrackUrl("http://dl.free.fr" & $oForm.action)
         Local $Host = $URL[2]
         Local $Port = $URL[3]
         Local $Referrer = "http://" & $URL[2]
         Local $QueryString = $URL[6] & $URL[7]
         Local $email = InputBox("Envoie de fichier sur Free", _
                 "On y va !!!" & @LF & @LF & _
                 "http://dl.free.fr" & $oForm.action & @LF & @LF & _
                 "Entrez votre adresse email" & @LF & _
                 "pour être notifié par free de l'adresse pour le télécharger.", "", "", 360, -1)
         If $email  = "" Then Return
     
         Local $hRequest = _WinHttpOpenRequest($hConnect, "POST", $QueryString, "HTTP/1.1", $Referrer)
         Local $form_files[1][2] = [["ufile", @TempDir & "\capture.jpg"]]
         Local $form_fields [7][2] = [ _
             ["mail1", $email], _
             ["mail2", ""], _
             ["mail3", ""], _
             ["mail4", ""], _
             ["message", "Test AutoIt"], _
             ["password", ""], _
             ["submit", "Envoyer"]]
         Local $FormDatas = Encode_MultiPart_FormData($form_fields, $form_files)
         Local $content_type = 'Content-Type: ' & $FormDatas[0] & @CRLF
         _WinHttpSendRequest($hRequest, $content_type, $WINHTTP_NO_REQUEST_DATA, StringLen($FormDatas[1]))
         _WinHTTPWriteData($hRequest, StringToBinary($FormDatas[1]), 1)
     
         _WinHttpReceiveResponse($hRequest)
         Local $post[3] = ["", _WinHttpQueryHeaders($hRequest), _WinHttpQueryOption($hRequest, $WINHTTP_OPTION_URL)]
         If _WinHttpQueryDataAvailable($hRequest) Then
     
         EndIf
    ; Pour la gestion du refresh en attente du retour serveur sur le traitement du fichier
         _WinHttpCloseHandle($hRequest)
         _WinHttpCloseHandle($hConnect)
         _WinHttpCloseHandle($hOpen)
     
    ; Comme la page de free fais un refresh toute les 2 secondes
    ; je lui Donne l'adresse de la page au lieu du HTML source
         _IENavigate($oIE, $post[2])

         _Debug($post[1] & $post[2] & @LF)
     EndFunc ;==>_Post_Files
     #Region;============= Fonctions ==========================
     #Region;; GUIEvent
     Func _GUIEvent_Quit()
         Exit
     EndFunc ;==>_GUIEvent_Quit
     
     Func _GUIEvent_Resize()
         Local $Size = WinGetClientSize($hGUI, "")
         GUICtrlSetPos($hIE, 5, 5, $Size[0] - 10, $Size[1] - 10)
     EndFunc ;==>_GUIEvent_Resize
     
     Func _IENavigateComplete($URL)
         _IENavigate($oIE, $URL)
         While Not $LoadComplete
             Sleep(10)
         WEnd
     EndFunc ;==>_IENavigateComplete
     
     Func _My_WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
         _GUIEvent_Resize()
         Return $GUI_RUNDEFMSG
     EndFunc ;==>_My_WM_SIZE
     #EndRegion
     #Region;; IEEvent
     Func _IEEvent_BeforeNavigate2($pDisp, $vUrl, $vFlags, $vTargetFrameName, $vPostData, $vHeaders, $bCancel)
;~   _DebugPrint("_IEEvent_BeforeNavigate2(""" & $vUrl & """)")
         $LoadComplete = False
     EndFunc ;==>_IEEvent_BeforeNavigate2
     
     Func _IEEvent_DocumentComplete($pDisp, $sURL)
         $LoadComplete = True
;~   _Debug("_IEEvent_DocumentComplete()")
     EndFunc ;==>_IEEvent_DocumentComplete
     
     Func _IEEvent_DownloadComplete()
;~   _DebugPrint("_IEEvent_DownloadComplete()")
     EndFunc ;==>_IEEvent_DownloadComplete
     
     Func _IEEvent_NavigateComplete2($pDisp, $sURL)
;~   _DebugPrint("_IEEvent_NavigateComplete2(""" & $sURL & """)")
         If StringInStr($sURL, "java script:") Then Return
         $URL = $sURL
     EndFunc ;==>_IEEvent_NavigateComplete2
     
     Func _IEEvent_ProgressChange($Progress, $ProgressMax)
;~   _DebugPrint("_IEEvent_ProgressChange(""" & $Progress & ", " & $ProgressMax & """)")
         ConsoleWrite($Progress & ", " & $ProgressMax & " ")
         If $Progress = -1 Then
             ConsoleWrite("Chargement de la page terminé" & @LF)
         EndIf
         If $ProgressMax = 0 Then
             ConsoleWrite("Chargement de la page... " & @LF)
         EndIf
         Local $percent = Int(($Progress * 100) / $ProgressMax)
         If $Progress > 0 Then
             ConsoleWrite($percent & "%" & @LF)
         EndIf
     EndFunc ;==>_IEEvent_ProgressChange
     
     Func _IEEvent_StatusTextChange($sText)
;~   _DebugPrint("_IEEvent_StatusTextChange(""" & $sText & """)")
         If $sText = "" Then $sText = "Prêt"
     EndFunc ;==>_IEEvent_StatusTextChange
     
     Func _IEEvent_TitleChange($sText = "")
;~   _DebugPrint("_IEEvent_TitleChange(""" & $sText & """)")
         If $sText = "" Then $sText = _IEPropertyGet($oIE, "title")
         WinSetTitle($hGUI, "", $Titre_Appli & $sText)
     EndFunc ;==>_IEEvent_TitleChange
     #EndRegion
     #Region;; Debug
     Func _Debug($title, $line = @ScriptLineNumber, $scriptfile = @ScriptName)
         Local $debug
         $debug &= $title & @LF
         $debug &= _IEPropertyGet($oIE, "title") & "(" & _IEPropertyGet($oIE, "locationurl") & ")" & @LF
         _IEFrameGetCollection($oIE)
         $debug &= "Nb de frame: " & @extended & @LF
         _IEImgGetCollection($oIE)
         $debug &= "Nb d'image: " & @extended & @LF
         _IELinkGetCollection($oIE)
         $debug &= "Nb de lien: " & @extended & @LF
     
         Local $oForms = _IEFormGetCollection($oIE)
         $debug &= "Nb de formulaire: " & @extended & @LF
         For $oForm In $oForms
             Local $Items = _IEFormElementGetCollection($oForm)
             $debug &= @LF & "++Form: " & $oForm.name & " Action: " & $oForm.action & @LF
             For $Item In $Items
                 $debug &= @TAB & "<" & $Item.type & "> Name: " & $Item.name
                 If $Item.type = "file" Then
                     $debug &= " file: désactivé non affiché " & $Item.value & @LF
                 ElseIf $Item.type = "textarea" Then
                     $debug &= " Value: textarea non affiché" & @LF
                 Else
                     $debug &= " Value=" & $Item.value & @LF
                 EndIf
             Next
         Next
         _DebugPrint($debug, $line, $scriptfile)
     EndFunc ;==>_Debug
     
     Func _DebugPrint($s_text, $line = @ScriptLineNumber, $scriptfile = @ScriptName)
         ConsoleWrite( _
                 "!===========================================================" & @LF & _
                 $scriptfile & "(" & $line & ",1) AutoIt " & @AutoItVersion & @LF & _
                 "+======================================================" & @LF & _
                 "" & $s_text & @LF & _
                 "+======================================================" & @LF)
     EndFunc ;==>_DebugPrint
     #EndRegion
     #EndRegion;===============================================
Edited by GaRydelaMer
Link to comment
Share on other sites

Anything is possible, but I don't see how it could be affected by some used function from WinHTTP.au3.

...String returned by _WinHttpQueryOption($hRequest, $WINHTTP_OPTION_URL) is null terminated for sure, even more than it should be (lol).

Can you post Encode_MultiPart_FormData() function too? Why aren't you reading in binary mode?

Btw, nice script.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Can you post Encode_MultiPart_FormData() function too? Why aren't you reading in binary mode?

I think, it's from my UDF: http://www.autoitscript.com/forum/index.ph...st&p=610967

*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

Hello Thx for reply

@ ProgAndy: Yes i use you're function Encode_MultiPart_FormData()

I don't thing it was null termainating in "_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_URL)"

I look fine the WebPage and she's refresh along the server want's to scan the file.

But i can't click on links !!! AuToIt Crash !!! The problem it's with IE object perhaps ?

I have this text in the console.

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "A:\Vidéothèque delaMer\src\WebBrowser2.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams   
   +>20:47:42 Starting AutoIt3Wrapper v.1.10.1.14   Environment(Language:040C  Keyboard:0000040C  OS:WIN_VISTA/Service Pack 1  CPU:X86  ANSI)
   >Running AU3Check (1.54.14.0)  from:C:\Program Files\AutoIt3
   +>20:47:45 AU3Check ended.rc:0
   >Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "A:\Vidéothèque delaMer\src\WebBrowser2.au3"   
   
   IE Event => about:blank
   -1, 0 Chargement de la page terminé
   
   1/ Write HTML from http://dl.free.fr/index_nojs.pl
   _Debug($post[1] & "'" & $post[2] & "'" & @LF)
   !===========================================================
   WebBrowser2.au3(119,1) AutoIt 3.3.0.0
   +======================================================
   HTTP/1.1 200 OK
   Date: Thu, 16 Apr 2009 18:56:54 GMT
   Server: Apache/1.3.41 (Unix) mod_perl/1.31-dev
   Expires: Thu, 29 Oct 1998 17:04:19 GMT
   Cache-Control: no-cache, no-store, must-revalidate
   Connection: close
   Transfer-Encoding: chunked
   Content-Type: text/html
   
   'http://dl.free.fr/index_nojs.pl'
   
   Free - Envoyez vos documents(http:///)
   Nb de frame: 0
   Nb d'image: 0
   Nb de lien: 56
   Nb de formulaire: 2
   
   ++Form: 0 Action: http://search.free.fr/google.pl
       <text> Name: qs Value=0
       <radio> Name: choose Value=wld
       <radio> Name: choose Value=fr
       <submit> Name: 0 Value=> Rechercher
   
   ++Form: 0 Action: /upload.pl?j04454995253230360894735771848438
       <file> Name: ufile file: désactivé non affiché 0
       <text> Name: mail1 Value=0
       <text> Name: mail2 Value=0
       <text> Name: mail3 Value=0
       <text> Name: mail4 Value=0
       <textarea> Name: message Value: textarea non affiché
       <text> Name: password Value=0
       <submit> Name: 0 Value=Envoyer
   
   +======================================================
   
   2/ Form Post And Redirect To http://dl.free.fr/mon.pl?i=3270022&h=Vy45GRau
   -1, 0 Chargement de la page terminé
   Chargement de la page... 
   0, 0 Chargement de la page... 
   !===========================================================
   WebBrowser2.au3(162,1) AutoIt 3.3.0.0
   +======================================================
   HTTP/1.1 200 OK
   Date: Thu, 16 Apr 2009 18:57:14 GMT
   Server: Apache/1.3.41 (Unix) mod_perl/1.31-dev
   Connection: close
   Transfer-Encoding: chunked
   Content-Type: text/html
   
   'http://dl.free.fr/mon.pl?i=3270022&h=Vy45GRau'
   
   Free - Envoyez vos documents(http://dl.free.fr/mon.pl?i=3270022&h=Vy45GRau)
   Nb de frame: 0
   Nb d'image: 3
   Nb de lien: 57
   Nb de formulaire: 1
   
   ++Form: 0 Action: http://search.free.fr/google.pl
       <text> Name: qs Value=0
       <radio> Name: choose Value=wld
       <radio> Name: choose Value=fr
       <submit> Name: 0 Value=> Rechercher
   
   +======================================================
   -1, 1000000 Chargement de la page terminé
  ;;;;; Serveur Free scaning from virus
   0, 0 Chargement de la page... 
   -1, 1000000 Chargement de la page terminé
   
  ;;;;; Page refresh: <body onload="java script:window.refresh">
   0, 0 Chargement de la page... 
   -1, 0 Chargement de la page terminé
   
  ;;;;; The end Page, Confirm Ok
   !>20:58:51 AutoIT3.exe ended.rc:-1073741819
   +>20:58:52 AutoIt3Wrapper Finished
   >Exit code: -1073741819  Time: 134.769
   
   AutoIt Crash If i click a link In this page.
Edited by GaRydelaMer
Link to comment
Share on other sites

Hi everybody,

I have problems downloading larger binary files, like images.

$hw_open = _WinHttpOpen("WinHTTP Example")

$hw_connect = _WinHttpConnect($hw_open, "192.168.2.2")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "/image.gif", "HTTP/1.1")
_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    $rData = _WinHttpReadData($h_openRequest, 2, 1000000 )
    ConsoleWrite( "Len: " & BinaryLen( $rData ) & @CRLF )
EndIf
_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
Exit

The Image is around 33kB and it takes roughly 10 seconds until the ConsoleWrite output appears.

In Wireshark I can see that the request is served within a couple of milliseconds.

Debugging showed my that the ReadData call takes the most time.

Is there something I am missing?

Thanks

aboy

Link to comment
Share on other sites

Hi

Try this ^_^

Global $hw_open = _WinHttpOpen("WinHTTP Example")

Global $hw_connect = _WinHttpConnect($hw_open, "localhost")
Global $h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "/css/images/banniere_fixe_zazouminiwebserver.jpg", "HTTP/1.1")
_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
    Global $rData = _WinHttpReadData($h_openRequest, 2), $temp
    While 1
        $temp = _WinHttpReadData($h_openRequest, 2)
        If BinaryLen($temp) = 0 Then ExitLoop
        ConsoleWrite("Len 1: " & BinaryLen($temp) & @CRLF)
        $rData = _WinHttpBinaryConcat($rData, $temp)
    WEnd
    $temp = ""
EndIf
ConsoleWrite("Total Len: " & BinaryLen($rData) & @CRLF)

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
Exit
Edited by GaRydelaMer
Link to comment
Share on other sites

I found out, that _WinHttpBinaryConcat is not needed. You can append a binary Variabel to another with & ^_^

1) Create an empty binary variable:

$Bin = Binary("")

2) Append Binary Data

$Bin &= Binary("0x1254AB")

$Bin &= Binary("0x1254AB")

;)

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

Yes. Open it in Binary (over)write mode and then write Binary data ^_^

*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

Hi guys, thanks for the reply.

It still lags a lot, her is my current loop:

If _WinHttpQueryDataAvailable($h_openRequest) Then
    While 1
        $tempData = _WinHttpReadData($h_openRequest, 2 )
        $rData &= $tempData
        ConsoleWrite("Len 1: " & BinaryLen($tempData) & @CRLF)
        If $tempData = 0 Then 
            ExitLoop 
        EndIf
    WEnd
    ConsoleWrite( "Len total: " & BinaryLen( $rData ) & @CRLF )
EndIf

And that's the Console output:

Len 1: 8192
Len 1: 8192
Len 1: 8192
Len 1: 356
Len 1: 0
Len total: 24932
>Exit code: 0   Time: 15.393

The output of the last block of data (356bytes) takes really long, the ones before are immediately there.

Thanks

aboy

Link to comment
Share on other sites

For me.

My WebServer for testing, is ZMWS on my USB Key, Freeware & open source support php and mysql and a custom handler and virtualhosts.

ex: in the configuration file: Handler:bat="C:\\winnt\\system32\\cmd.exe /C"

# The Document Root, where the virtual host files are located

# (absolute or relative to server dir)

# default is _vhosts.zmwsc/domain relative to main server's webdir

# VirtualHost:mycompany.com:webdir=_web.zmwsc/_vhosts.zmwsc/mycompany.com

ZMWS

Len 1: 8192
Len 1: 8192
Len 1: 255
Total Len: 24831
>Exit code: 0   Time: 4.630

With a jpg image.

If _WinHttpQueryDataAvailable($h_openRequest) Then
    Global $tempData = Binary("")
    Global $rData = _WinHttpReadData($h_openRequest, 2)
    While 1
        $tempData = _WinHttpReadData($h_openRequest, 2)
        If BinaryLen($tempData) = 0 Then ExitLoop
        ConsoleWrite("Len 1: " & BinaryLen($tempData) & @CRLF)
        $rData &= $tempData
    WEnd
    $tempData = Binary("")
EndIf
ConsoleWrite("Total Len: " & BinaryLen($rData) & @CRLF)

FileWrite("toto.jpg", $rData)

If you look in my console, i haven't this Line: Len 1: 0, because i'm exiting while before you.

Edited by GaRydelaMer
Link to comment
Share on other sites

I found out, that _WinHttpBinaryConcat is not needed. You can append a binary Variabel to another with & ^_^

1) Create an empty binary variable:

$Bin = Binary("")

2) Append Binary Data

$Bin &= Binary("0x1254AB")

$Bin &= Binary("0x1254AB")

;)

Well of course. But that's not documented feature. I never read that one of the devs said you should/could concat two binary datas like that. Help file lacks that information too.

It was mentioned here by some Jon (who the fuc*k is he???) and that was ending with question mark.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Well, i always missed that, but it should be faster than the concat-func and aboy wants his code to be fast ^_^

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

Okay, so I ran my code and the one from GaRydelaMer

on an other machine (XP in a Parallels VM) and it runs smoothly...

Something must be wrong with my other PC at work. I'll check next Monday.

What I can say is that there are 2 network cards installed, hope that is not a problem...

Thanks for now!

aboy

Link to comment
Share on other sites

Hi guys,

back at work I tried the code again and still had the lag with the last data call of _WinHttpReadData()

I just found out that the problem is indeed with my network cards. I have an internal one and

an external USB2Ethernet converter. The images are on a device that is connected to the USB2Ethernet converter.

When I remove the converter and request the data from a local running webserver,

the calls return pretty quickly. The same happens when I request data from a webserver

bound to the internal network card.

Any ideas if the winhttp.dll could cause the problems?

aboy

Link to comment
Share on other sites

I think, your device connected to your USB2Ethernet is not sending the size of the data to receive. Then WinHTTP waits until a timeout occurs, since it doesn't know when the transmission is complete.

*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

This are bad news.. :-(

I tried the http.au3 UDF as well and it is faster but still slow compared to using wget.exe:

$wgetargs = "-O image.gif http://" & "192.168.3.88" & "/image.gif"          
ShellExecuteWait("wget.exe", $wgetargs , "", "", @SW_HIDE )

Works via the file system but that would have been the case with other UDFs

like winhttp.au3 or http.au3 as well... when we talk about binary files.

Thanks anyway,

aboy

Link to comment
Share on other sites

@aboy, try running this:

#include <WinHTTP.au3>

Global $hHttpOpen = _WinHttpOpen()
If @error Then
    MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
    Exit
EndIf

Global $hHttpConnect = _WinHttpConnect($hHttpOpen, "192.168.2.2")
If @error Then
    MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
    _WinHttpCloseHandle($hHttpOpen)
    Exit
EndIf

Global $hHttpRequest = _WinHttpOpenRequest($hHttpConnect, "GET", "image.gif")
If @error Then
    MsgBox(48, "Error", "Error creating an HTTP request handle.")
    _WinHttpCloseHandle($hHttpConnect)
    _WinHttpCloseHandle($hHttpOpen)
    Exit
EndIf

_WinHttpSendRequest($hHttpRequest)
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    _WinHttpCloseHandle($hHttpConnect)
    _WinHttpCloseHandle($hHttpOpen)
    Exit
EndIf

_WinHttpReceiveResponse($hHttpRequest)

If _WinHttpQueryDataAvailable($hHttpRequest) Then
    ConsoleWrite(_WinHttpQueryHeaders($hHttpRequest))
Else
    ConsoleWrite("! Nothing available." & @CRLF)
EndIf

_WinHttpCloseHandle($hHttpRequest)
_WinHttpCloseHandle($hHttpConnect)
_WinHttpCloseHandle($hHttpOpen)

ProgAndy could be right (as usual ^_^ )

edit:

Don't forget to post console output

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Hi trancexx, here you are:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Projects\AutoIt\winHTTPTest2.au3" 
HTTP/1.1 200 OK
server: embeddedWebServer/0.0.1
content-length:35266
connection:close
Content-Type: image/gif
Content-disposition: attachment; filename=image.gif

>Exit code: 0   Time: 0.433

aboy

Edited by aboy
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...