Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

Wow, never saw this before...

Note that not only a named variable can be passed for a ByRef parameter; unnamed temporary variables, such as function return values, may be passed as ByRef parameters as well. A literal can not be passed to a ByRef parameter.

Does Jos still maintain au3check? Seems like it needs some updating.
Link to comment
Share on other sites

Hi guys,

I got a problem with the function on Win 8 64 bit:

_WinHttpOpenRequest($hConnectWinHttp, "POST", $target_URL)

When I compile 64bit and run compiled.exe it will crash the winhttp.dll

if I compile/run with x86/32 bit it works fine. I found out that the parameter for $hConnectWinHttp is an 64bit int

and thats what win 8 doesn´t like. so what can I do ? and why does that work in win7 64bit without that problems ?

greetings

Link to comment
Share on other sites

I run v3.3.8.1 and that´s the first problem I ve had running autoit on Win 8

This is my script:

EDIT: cutting down the handle to int32 doesn´t work ... maybe the problem is another but crashing will be at that function _WinHttpOpenRequest.

#AutoIt3Wrapper_UseX64=y


#include <WinHTTP.au3>
#include <base64.au3>

$crypted_file = FileOpenDialog("Select crypted logfile", @ScriptDir, "Logfiles (*.*)", 1)
$connect_to_server = "xxxxxserver.de"
$target_URL = "upload-test.php"

MsgBox(0, "ergebnis", _send_post_binary($connect_to_server, $target_URL, $crypted_file))

func _send_post_binary($connect_to_server, $target_URL, $binaryfiledata, $file_send_to_server = "binary.exe", $sBoundary = "XXX", $encodebase64 = 1 )

;~ ; Initialize and get session handle
;~ Local $hOpenWinHttp = _WinHttpOpen()
;~ ; Get connection handle
;~ Local $hConnectWinHttp = _WinHttpConnect($hOpenWinHttp, $connect_to_server)
;~ ; Specify the reguest
;~ Local $hRequestWinHttp = _WinHttpOpenRequest($hConnectWinHttp, "POST", $target_URL)


; Initialize and get session handle
Local $hOpenWinHttp = _WinHttpOpen()
MsgBox(1,"$hOpenWinHttp",$hOpenWinHttp)
; Get connection handle
Local $hConnectWinHttp = _WinHttpConnect($hOpenWinHttp, $connect_to_server)
MsgBox(1,"$hConnectWinHttp",$hConnectWinHttp)
; Specify the reguest
Local $hRequestWinHttp = _WinHttpOpenRequest($hConnectWinHttp, "POST", $target_URL)
MsgBox(1,"$hRequestWinHttp",$hRequestWinHttp)


;~ --------------------------------------------------------
Local $base64Stuff, $sS

$base64Stuff = Base64Encode(FileRead($binaryfiledata))


$sS = @CRLF & "--" & $sBoundary & @CRLF
$sS &= 'Content-Disposition: multipart/form-data; name="userfile"; filename="' & $file_send_to_server & '"' & @CRLF
$sS &= 'Content-Transfer-Encoding: base64' & @CRLF
$sS &= "Content-Type: text/plain" & @CRLF & @CRLF & $base64Stuff & @CRLF
$sS &= "--" & $sBoundary & "--" & @CRLF

;MsgBox(0,"SS", $sS)

; Send request
Local $hSendRequestWinHttp = _WinHttpSendRequest($hRequestWinHttp, "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF, $sS, StringLen($sS))

; Wait for the response
_WinHttpReceiveResponse($hRequestWinHttp)
Local $recieived_data = _WinHttpReadData($hRequestWinHttp)

; Close handles
_WinHttpCloseHandle($hRequestWinHttp)
_WinHttpCloseHandle($hConnectWinHttp)
_WinHttpCloseHandle($hOpenWinHttp)

; Check if there is data available...
If _WinHttpQueryDataAvailable($hRequestWinHttp) Then
Return $recieived_data
Else
Return $recieived_data
EndIf

EndFunc
Edited by WhiteLion
Link to comment
Share on other sites

Sure, no problem. It was kind of obvious that something was wrong with the files you were using, either older versions of AutoIt or the UDF. Really, how did you manage to download the wrong version? Isn't the OP and the intro clear enough? Maybe I should edit to make it more clear?

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Maybe I should edit to make it more clear?

It's pretty clear transexx.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 5 weeks later...

hi guy

i have a dlink nas , i use it , for download torrent , but i must often go by browser in page of torrent for add new torrent , and i wanna create a little script for do this in 2 clik , i sniff the http request i just enter and select good page but ,i dont understund how add torrent file

this is http request

----------------------------------------------------------
http://192.168.1.7/cgi-bin/p2p_upload.cgi
POST /cgi-bin/p2p_upload.cgi HTTP/1.1
Host: 192.168.1.7
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:18.0) Gecko/20130119 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: username=admin
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------15913953313213
Content-Length: 18250
-----------------------------15913953313213
Content-Disposition: form-data; name="cmd"
p2p_add_torrent_file_new
-----------------------------15913953313213
Content-Disposition: form-data; name="path"
-----------------------------15913953313213
Content-Disposition: form-data; name="f_torrent_file"; filename="[rutracker.org].t4289263.torrent"
Content-Type: application/x-bittorrent
d8:announce42:http://bt4.rutracker.org/ann?uk=okQwpSz4gG13:announce-listll42:http://bt4.rutracker.org/ann?uk=okQwpSz4gGel31:http://retracker.local/announceee7:comment50:http://rutracker.org/forum/viewtopic.php?t=428926310:created by13:uTorrent/323013:creation datei1359320456e8:encoding5:UTF-84:infod5:filesld6:lengthi6386702e4:pathl15:00 Introduction16:0001 Welcome.moveed6:lengthi1318e4:pathl15:00 Introduction16:0001 Welcome.srteed6:lengthi4024698e4:pathl15:00 Introduction33:0002 Using the exercise files.moveed6:lengthi5114e4:pathl15:00 Introduction33:0002 Using the exercise files.srteed6:lengthi1171268e4:pathl15:00 Introduction29:0003 What you should know.moveed6:lengthi1578e4:pathl15:00 Introduction29:0003 What you should know.srteed6:lengthi7630176e4:pathl25:01 Built-In PHP Debugging52:0101 Exploring PHP error levels and consequences.moveed6:lengthi9747e4:pathl25:01 Built-In PHP Debugging52:0101 Exploring PHP error levels and consequences.srteed6:lengthi14361598e4:pathl25:01 Built-In PHP Debugging50:0102 Configuring PHP to report what went wrong.moveed6:lengthi13499e4:pathl25:01 Built-In PHP Debugging50:0102 Configuring PHP to report what went wrong.srteed6:lengthi7479222e4:pathl25:01 Built-In PHP Debugging31:0103 Logging errors to file.moveed6:lengthi6801e4:pathl25:01 Built-In PHP Debugging31:0103 Logging errors to file.srteed6:lengthi15896962e4:pathl25:01 Built-In PHP Debugging44:0104 Triggering and repairing PHP errors.moveed6:lengthi13264e4:pathl25:01 Built-In PHP Debugging44:0104 Triggering and repairing PHP errors.srteed6:lengthi8784511e4:pathl25:01 Built-In PHP Debugging41:0105 Gracefully handling fatal errors.moveed6:lengthi6302e4:pathl25:01 Built-In PHP Debugging41:0105 Gracefully handling fatal errors.srteed6:lengthi6112744e4:pathl25:01 Built-In PHP Debugging31:0106 Deciphering backtraces.moveed6:lengthi5397e4:pathl25:01 Built-In PHP Debugging31:0106 Deciphering backtraces.srteed6:lengthi2215695e4:pathl21:02 Introducing Xdebug47:0201 What is Xdebug and how can it be used-.moveed6:lengthi2879e4:pathl21:02 Introducing Xdebug47:0201 What is Xdebug and how can it be used-.srteed6:lengthi13179841e4:pathl21:02 Introducing Xdebug40:0202 Installing the Xdebug extension.moveed6:lengthi4231e4:pathl21:02 Introducing Xdebug40:0202 Installing the Xdebug extension.srteed6:lengthi10778453e4:pathl21:02 Introducing Xdebug41:0203 Displaying variables with Xdebug.moveed6:lengthi6631e4:pathl21:02 Introducing Xdebug41:0203 Displaying variables with Xdebug.srteed6:lengthi13154288e4:pathl21:02 Introducing Xdebug46:0204 Exploring remote debugging principles.moveed6:lengthi5486e4:pathl21:02 Introducing Xdebug46:0204 Exploring remote debugging principles.srteed6:lengthi7253530e4:pathl21:02 Introducing Xdebug46:0205 Xdebug remote debugging with NetBeans.moveed6:lengthi4995e4:pathl21:02 Introducing Xdebug46:0205 Xdebug remote debugging with NetBeans.srteed6:lengthi9912845e4:pathl21:02 Introducing Xdebug50:0206 Profiling performance to find bottlenecks.moveed6:lengthi9046e4:pathl21:02 Introducing Xdebug50:0206 Profiling performance to find bottlenecks.srteed6:lengthi15201893e4:pathl29:03 Debugging from the Browser51:0301 Extending Firefox with Firebug and FirePHP.moveed6:lengthi10894e4:pathl29:03 Debugging from the Browser51:0301 Extending Firefox with Firebug and FirePHP.srteed6:lengthi10834095e4:pathl29:03 Debugging from the Browser30:0302 Integrating ChromePHP.moveed6:lengthi6372e4:pathl29:03 Debugging from the Browser30:0302 Integrating ChromePHP.srteed6:lengthi11779339e4:pathl29:03 Debugging from the Browser51:0303 Using PHP_Debug to debug without a console.moveed6:lengthi8088e4:pathl29:03 Debugging from the Browser51:0303 Using PHP_Debug to debug without a console.srteed6:lengthi3174596e4:pathl13:04 Conclusion23:0401 Best practices.moveed6:lengthi3933e4:pathl13:04 Conclusion23:0401 Best practices.srteed6:lengthi1655559e4:pathl13:04 Conclusion30:0402 Where to go from here.moveed6:lengthi2049e4:pathl13:04 Conclusion30:0402 Where to go from here.srteed6:lengthi1061089e4:pathl13:04 Conclusion16:0403 Goodbye.moveed6:lengthi1207e4:pathl13:04 Conclusion16:0403 Goodbye.srteed6:lengthi3720333e4:pathl31:Ex_Files_Debug_PHP_Adv_Tech.zipeee4:name45:Lynda.com - Debugging PHP Advanced Techniques12:piece lengthi262144e6:pieces13420:9^t¥­èÖ?½9†‘^Š÷8ïv`í-MWÆz$  ;†‘óöɈ^÷ÝÁ`Êàn:™ï¬ï©”4Ÿ¥
9ÒÉvg–ß IÊ2^e„$Ôo®LzNX–íné+˜ üÃñàÛ•O÷[Êó(*˜á³ÅŒ :ËYk]–6OO,”ï1‘Ć™ˆ‘­RkXþ^í«”ç¸›„®¤o§©k51ƨ9€ƒ¹KŸà%;ø„~éŽ}؆Ê
#•¹F©™«ý–B Uö×Ä »q³È«Ýˆ½ËjJÄѨŸ(õOçw8.”~S×
QÛ™ºkTL»›"ѧ<„ ±p³“‹°=Ă»O§j]¾®P…EEfi{XxV߬Ä/òš±õ9ìxî†!F<MÑÈ iñÝ>XFÊîýÀƛ¿¢°»N¨•?æÛ²’ ˆ~ð¢†æDà 5-1ÔÎÙìnÛ[¼%•Ô¤µiZ·×ù’“rñ«°aȵ"’€}æ7j!ßœ÷í÷hã<ᶑÞý½„‹>¬ž±ðÁšâ`W$Ò~ö Í4ð,¦Êr§9ŽÃ8ÛÜh3x&3Ƨœ;=PeK 2znÚ‚Ñ «ˆÆ|4rË’àP€‰¼…YµšøýdO0«ÎÚCÇIEØQÓ0²gŒ”(þ"ÌJÿiâ}ùą
HTTP/1.1 200 OK
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/xml
Transfer-Encoding: chunked
Date: Sat, 27 Apr 2013 16:40:06 GMT
Server: lighttpd/1.4.25-devel-fb150ff
----------------------------------------------------------

i have tryed to format in this mode but dont go

http://192.168.1.7/cgi-bin/p2p_upload.cgi?cmd=p2p_add_torrent_file_new&path&filename=C:UsersstefanoDesktop[rutracker.org].t4289263.torrent

http://192.168.1.7/cgi-bin/p2p_upload.cgi?cmd=p2p_add_torrent_file_new&path=&f_torrent_file=[rutracker.org].t4289263.torrent

thankz :)

Link to comment
Share on other sites

How do I retrieve an error code or message from _winhttp_* functions?

I get @error=1, but what is the cause?

More precisely, I seem to get some HTTP 4XX error, but do not know which one, so I don't know what to fix.

Edit:

Actually, _WinHttpQueryHeaders($request) worked, but I was getting a connection error instead of HTTP error (could not connect to host)

How do I detect errors connecting to server?

Edited by Shambler0
Link to comment
Share on other sites

hi

here's my script:

#include <Array.au3>
#include <WinHttp.au3>

Opt("MustDeclareVars", 1)

Global $hOpen, $hConnect, $sRead2
Global $sRead, $hFileHTM, $sFileHTM = @ScriptDir & "\Form.htm"
Global $aURL[8] = ["http", 1, "www.site.come", 80, "", "", "/upload.php", "?cat=25"]
Global $test = _WinHttpCreateUrl($aURL)
$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "site.com")
$sRead = _WinHttpSimpleFormFill($hConnect, "/login.php", 0, "name:username", "***", "name:password", "***")
;~ ConsoleWrite($sRead)
;~ MsgBox(0, "test", "next stage")
$sRead2 = _WinHttpSimpleFormFill($hConnect, "/upload.php?cat=25", "", "name:file", @DesktopDir & "\PICTURE00002516.JPG", "name:name", "test", "name:descr", "test descr")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
ConsoleWrite($sRead2)

However the request is sent to site.com/upload.php, not to upload.php?cat=25. If I use _WinHttpCreateUrl($aURL), I can't find out what is being sent send and since the script fails, I suppose it is not "site.com/upload.php?cat=25". What should I correct in the script?

Edited by hiho
Link to comment
Share on other sites

hi

here's my script:

#include <Array.au3>
#include <WinHttp.au3>

Opt("MustDeclareVars", 1)

Global $hOpen, $hConnect, $sRead2
Global $sRead, $hFileHTM, $sFileHTM = @ScriptDir & "\Form.htm"
Global $aURL[8] = ["http", 1, "www.site.come", 80, "", "", "/upload.php", "?cat=25"]
Global $test = _WinHttpCreateUrl($aURL)
$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "site.com")
$sRead = _WinHttpSimpleFormFill($hConnect, "/login.php", 0, "name:username", "***", "name:password", "***")
;~ ConsoleWrite($sRead)
;~ MsgBox(0, "test", "next stage")
$sRead2 = _WinHttpSimpleFormFill($hConnect, "/upload.php?cat=25", "", "name:file", @DesktopDir & "\PICTURE00002516.JPG", "name:name", "test", "name:descr", "test descr")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
ConsoleWrite($sRead2)

However the request is sent to site.com/upload.php, not to upload.php?cat=25. If I use _WinHttpCreateUrl($aURL), I can't find out what is being sent send and since the script fails, I suppose it is not "site.com/upload.php?cat=25". What should I correct in the script?

There is no such thing as something/upload.php?cat=25. What's after question mark character is GET method data.

That means that the code on page /upload.php will receive cat=25 as GET data and form data you fill as POST data.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Um, trancexx, could you please tell me how to get any meaningful error codes out of winhttp functions?

hiho, it is best to make your script send data to a program that just logs everything sent, then do the same to a webbrowser

In other words, dump what your script sends, dump what firefox sends, compare.

Use example scripts for TcpRecv and TcpSend (replace gui functions and Inputbox with filewrite/fileread) to do the work of recieving/sending data.

Or you can probably use "netcat" program (download, manual)

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