Jump to content

Recommended Posts

Posted

You have to add the content-type-hedaer:

_WinHttpSendRequest($hRequest,"Content-Type: application/x-www-form-urlencoded" & @CRLF, $WINHTTP_NO_REQUEST_DATA, StringLen($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

Posted (edited)

And technically you don't need to use _WinHttpWriteData(). You can send this:

$data = "v=101" 

_WinHttpSendRequest($hRequest,"Content-Type: application/x-www-form-urlencoded", $data)

or:

$data = "v=101"
_WinHttpAddRequestHeaders($hRequest, "Content-Type: application/x-www-form-urlencoded")
_WinHttpSendRequest($hRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $data)
Edited by trancexx

♡♡♡

.

eMyvnE

Posted

WinHttpWriteData has been translated by trancexx and me.

Now, i#ll post WinHttpCrackUrl, WinHttpCreateUrl and WinHttpSetStatusCallback :mellow:

(examples in the files)

your callback example never work for me ?

73 108 111 118 101 65 117 116 111 105 116

Posted

your callback example never work for me ?

The example acutally doesn't do anything. It just sets the status callback and exits, you have to add some code on your own to use the status callback.

*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

Posted

The example acutally doesn't do anything. It just sets the status callback and exits, you have to add some code on your own to use the status callback.

I am not a pro in C++ , so any working example please ? Posted Image

73 108 111 118 101 65 117 116 111 105 116

Posted

Why do you need an other example?

This function is only useful if you want to do asynchronous WinHTTP-calls, that means sending a request without waiting for tehe response of the server. Then the callback will receive a message when the server has responded and your script can continue processing the response.

I think this techniue is rarely used.

*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

Posted

Why do you need an other example?

This function is only useful if you want to do asynchronous WinHTTP-calls, that means sending a request without waiting for tehe response of the server. Then the callback will receive a message when the server has responded and your script can continue processing the response.

I think this techniue is rarely used.

I am creating a Clint Service for updating the software (Automatic or Manual), which is controlled by the User Base GUI. So when the user send the request or the new update is avialible , it will start the update process & send the updating progress to the User Base GUI.

Before implementing this UDF i was using FTP & "internet Status Callback" function to show the progress, but i found that FTP is not enough secure, i mean i found some tools which can allocate detail about Opened Session of FTP, thats why i come to this UDF. I know that there is nothing impossible to hack, but through HTTP & PHP its a bit secure.

Now i want to implement the callback function, but in your example its always return the INVALID_HANDLE, thats why i am asking for working example.

73 108 111 118 101 65 117 116 111 105 116

  • 4 weeks later...
Posted

Thanks for this great UDF!

Is it possible somehow to check the progress when uploading/downloading files ( uploaded / downloaded bytes ) ? ...in my case uploading to/downloading from PHP.

THX!

  • 1 month later...
  • 2 weeks later...
  • 2 months later...
Posted

And the code is?

Func _POSTRequest($domain, $file, $query)
    Local $hOpen, $hConnect, $hRequest
    $hOpen = _WinHttpOpen()
    $hConnect = _WinHttpConnect($hOpen, $domain)
    $hRequest = _WinHttpOpenRequest($hConnect, "POST", $file)
    _WinHttpAddRequestHeaders($hRequest, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6")
    _WinHttpAddRequestHeaders($hRequest, "Content-Type: application/x-www-form-urlencoded")
    _WinHttpAddRequestHeaders($hRequest, "Connection: Keep-Alive")
    _WinHttpSendRequest($hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $query)
    _WinHttpReceiveResponse($hRequest)
    $hResponse = _WinHttpReadData($hRequest)
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    Return $hResponse
EndFunc

That's the function I use...it's only giving me back a 8192 of the response instead of the full response.

Posted (edited)

Func _POSTRequest($domain, $file, $query)
    Local $hOpen, $hConnect, $hRequest
    $hOpen = _WinHttpOpen()
    $hConnect = _WinHttpConnect($hOpen, $domain)
    $hRequest = _WinHttpOpenRequest($hConnect, "POST", $file)
    _WinHttpAddRequestHeaders($hRequest, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6")
    _WinHttpAddRequestHeaders($hRequest, "Content-Type: application/x-www-form-urlencoded")
    _WinHttpAddRequestHeaders($hRequest, "Connection: Keep-Alive")
    _WinHttpSendRequest($hRequest, $WINHTTP_NO_ADDITIONAL_HEADERS, $query)
    _WinHttpReceiveResponse($hRequest)
    $hResponse = _WinHttpReadData($hRequest)
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    Return $hResponse
EndFunc

That's the function I use...it's only giving me back a 8192 of the response instead of the full response.

No, not "instead".

That's the default behavior of _WinHttpReadData() function. I made sure that was documented, just read the header of that function.

Anyway, you have to read in a loop to get all of the response. For example:

;...
Local $sChunk, $sResponse
While 1
    $sChunk = _WinHttpReadData($hRequest)
    If @error Then ExitLoop
    $sResponse &= $sChunk
WEnd
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Return $sResponse
;...
Edited by trancexx

♡♡♡

.

eMyvnE

Posted (edited)

Thanks trancexx. New problem, LOL. Err, is WinHTTP not able to access localhost? The following code won't work...

#include "WinHTTP.au3"

$LocalIP = "localhost"
$hw_open = _WinHttpOpen()
$hw_connect = _WinHttpConnect($hw_open, $LocalIP)
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "/test.html")
_WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA)
_WinHttpReceiveResponse($h_openRequest)
MsgBox(0, "", _WinHttpReadData($h_openRequest))
_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)
Edited by motionman95

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...