hiho Posted May 3, 2013 Share Posted May 3, 2013 I did that. 2 days ago. expandcollapse popupGlobal $hRequest = _WinHttpOpenRequest($hConnect2, "POST", "/takeupload.php", Default, "/upload.php", "*/*") Global $boundary = Random(1000000000000, 99999999999999, 1) Global $sData = "" $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="MAX_FILE_SIZE"' & @CRLF & @CRLF $sData &= '1000000' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="type"' & @CRLF & @CRLF $sData &= "25" & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="file"; filename="1.torrent"' & @CRLF $sData &= 'Content-Type: application/x-bittorrent' & @CRLF & @CRLF $sData &= $fileread & @CRLF ;~ $sData &= FileRead(@DesktopDir & "\raw2.txt") & @CRLF ;~ $sData &= _Base64Encode(FileRead("C:UsersLykerDesktopOtherUntitled-1.png")) & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="name"' & @CRLF & @CRLF $sData &= 'imenatorenta' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="nfo"; filename="1.txt"' & @CRLF $sData &= 'Content-Type: text/plain' & @CRLF & @CRLF $sData &= 'nfoto' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="descr"' & @CRLF & @CRLF $sData &= 'opis' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="remLen"' & @CRLF & @CRLF $sData &= '14996' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="youtube"' & @CRLF & @CRLF $sData &= '' & @CRLF $sData &= '-----------------------------' & $boundary & @CRLF $sData &= 'Content-Disposition: form-data; name="google"' & @CRLF & @CRLF $sData &= '' & @CRLF $sData &= '-----------------------------' & $boundary & "--" ;~ ConsoleWrite($sData) $datasize = StringLen($sData) _WinHttpSendRequest($hRequest, "", $sData) _WinHttpReceiveResponse($hRequest) $sResult = _WinHttpReadData($hRequest) ClipPut($sResult) ConsoleWrite($sResult & @CRLF) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect2) _WinHttpCloseHandle($hOpen2) There are 2 additional heards Content-Length 15365 Content-Type multipart/form-data; boundary=---------------------------71902182822295 Which i'm not sure how to send.. _WinHttpSendRequest($hRequest, ADDITIONAL HEARDS HERE?, $sData) ? Link to comment Share on other sites More sharing options...
Shambler0 Posted May 3, 2013 Share Posted May 3, 2013 (edited) "Content-Length 15whatever5" is automatically calculated and sent by winhttp (it does that for me, at least) "Content-Type multipart/form-data; boundary=---------------------------71902182822295" - this one you MUST send yourself in order for this to work at all Probably the best way to do this is to use 2nd argument of _WinHttpSendRequest(): _WinHttpSendRequest( $hRequest, 'Content-Type: multipart/form-data; boundary=---------------------------' & $boundary & @CRLF , $sData ) Please notice that there are TWO LESS dashes. I tested it - it works! Edit: By the way, random() can output a maximum of 2147483648 -- but you can do this: Random(100000000, 999999999, 1) & Random(100000000, 999999999, 1) & Random(100000000, 999999999, 1) Edit2: Also just stumbled over a server that did not accept my query unless I included linefeed at the end of data like this: $sData &= '-----------------------------' & $boundary & "--" & @CRLF ; <<<<<<<<<<<<<<<<<<<< added CRLF Edited May 3, 2013 by Shambler0 Link to comment Share on other sites More sharing options...
trancexx Posted May 3, 2013 Author Share Posted May 3, 2013 Um, trancexx, could you please tell me how to get any meaningful error codes out of winhttp functions?Define meaningful.If you get error then you can call _WinAPI_GetLastError() to get extended information about the error. If the error is the API specific, GetLastError will return one of WinHTTP error codes defined inside WinHttpConstants.au3. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trancexx Posted May 3, 2013 Author Share Posted May 3, 2013 (edited) Ok. How should I edit the script so that it'll send "cat=25" to upload.php?I don't see anything terribly wrong with the code you already posted. I even tested it on my server and it worked just fine. Maybe you are doing something else wrong. Without seeing actual page it's impossible to tell for me. Edited May 3, 2013 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Shambler0 Posted May 3, 2013 Share Posted May 3, 2013 Ok, it seems that GetLastError() actually works in most cases. In my case ("POST" method, server does not reply) GetLastError() just returns zeroes, and then suddenly it starts returning ERROR_WINHTTP_INCORRECT_HANDLE_STATE I assumed I should call something other than GetLastError(), but have just looked at MSDN examples - they call GetLastError() So the question should be asked on MSDN instead of here. Sorry to bother you. Link to comment Share on other sites More sharing options...
Allow2010 Posted May 15, 2013 Share Posted May 15, 2013 (edited) Hi, first, let me thank you for this UDF, it helped me a lot in my projects. But today i came across a big problem using the UDF on Windows 8 64bit (did not test 32bit) I wrote this code $soResult = _WinHttpSetOption($hOpen, BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID)) If @error Or $soResult = 0 Then MsgBox(0,"","Error: _WinHttpSetOption failed with code " & @error) EndIf to access a site (router) that uses SSL but does not have a valid certificate. It all works just fine when run on Windows 7 64bit, but fails when run on Windows 8 64bit. The Error it gives me is error 4 (DLLCall failed). I tried setting other Options (like the useragent from the helpfile) and it works fine... Seems to be just a problem with $WINHTTP_OPTION_SECURITY_FLAGS on Win8. Can onyone help me, i am totally lost here and this breaks my code...i have not found a way around this problem yet... EDIT: FYI: runnig latest Autoit public BETA 3.3.9.4 and compiling in 32bit EDIT2: fixed bad copy and paste of the code...pasted a test code by mistake Edited May 16, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
Allow2010 Posted May 15, 2013 Share Posted May 15, 2013 (edited) $aCall returns the following (see picture) maybe someone knows what the values mean... I also took the Win7 winhttp.dll and renamed it to winhttp5.dll and put it in my system32 folder in my Windows 8 System. Then i changed Global Const $hWINHTTPDLL__WINHTTP = DllOpen("winhttp5.dll") DllOpen("winhttp5.dll") ; making sure reference count never reaches 0 in Winhttp.au3 and it works fine... So there has to be an incompatibillity with the Win8 winhttp version...maybe win8 made it harder to ignore certificates in an attempt to be more secure... I searched the net for changes in Winhttp but i could not find any useful documentation... Edited May 16, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
trancexx Posted May 16, 2013 Author Share Posted May 16, 2013 (edited) ^^ Is there possibility that you are doing something wrong? For example, what's the 1000 value that you set? Maybe you meant SECURITY_FLAG_IGNORE_CERT_CN_INVALID? That constant is declared inside WinHttpConstants.au3 and has value of 0x00001000. That's whole different value than the one you use. Next, why are you setting it for internet session? Try for specific request, usually named $hRequest. Edited May 16, 2013 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Allow2010 Posted May 16, 2013 Share Posted May 16, 2013 (edited) Thanks for your reply... the 1000 was just a bad copy and paste from my tries (i tried different values to see if i get different returncodes, but it is always 4) I replaced the code in the post above to prevent further irritation. the real code is $allow_unknownCA_wrongCN = BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID) $soResult = _WinHttpSetOption($hOpen, $WINHTTP_OPTION_SECURITY_FLAGS, $allow_unknownCA_wrongCN) If @error Or $soResult = 0 Then _FB_Logfile("Error: _WinHttpSetOption failed with code " & @error) Return 0 EndIf the codes is needed to connect to a router which uses a self signed certificate. It works just fin on Win7 and not in Win 8 (but works fine again when i use the win7 dll on win 8 as explained above) i am 100% certain that i am not doing anything wrong. You can see the complete project here: Next, why are you setting it for internet session? Try for specific request, usually named $hRequest. well that might be a good point. I did set it for the session as it is used globally throughout the complete connection and i only need to set it once. It works just fine on win7... I will try to set it for the request an will report back as soon as i can find the time...thank you again... Edited May 16, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
Allow2010 Posted May 16, 2013 Share Posted May 16, 2013 Yes you were right, thank you: on Win7 it is possible to do this $soResult = _WinHttpSetOption($hOpen, BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID)) on Win8 it will fail. when i do it this way, it works on Win8 $soResult = _WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS,BitOR($SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID)) so you tip helped my solve the issue, thank you! Link to comment Share on other sites More sharing options...
guinness Posted May 18, 2013 Share Posted May 18, 2013 (edited) The details about $pBuffer in _WinHttpReadData are missing from the documentation. Edited May 18, 2013 by guinness 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
trancexx Posted May 18, 2013 Author Share Posted May 18, 2013 The details about $pBuffer in _WinHttpReadData are missing from the documentation. That's intentional. That parameter is for internal use or for use by advanced memebers. Nice of you to notice. Really. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
hiho Posted June 2, 2013 Share Posted June 2, 2013 (edited) Hi trancexxx, if you've got a webpage with <input type="radio" value="no" name="test1"> <input type="radio" value="no" name="test2"> and want to send their value as "yes", how do you do that? I've read (the Remarks section) that it's removed from the _WinHttpSimpleFormFill function . I added "radio" to this line $aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3) but it won't change the value from no to yes. Edited June 2, 2013 by hiho Link to comment Share on other sites More sharing options...
trancexx Posted June 2, 2013 Author Share Posted June 2, 2013 Hi trancexxx, if you've got a webpage with <input type="radio" value="no" name="test1"> <input type="radio" value="no" name="test2"> and want to send their value as "yes", how do you do that? I've read (the Remarks section) that it's removed from the _WinHttpSimpleFormFill function . I added "radio" to this line $aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3) but it won't change the value from no to yes. You can't do that. The value of radio is preset. This is how browsers do it also. If you click the radio button the value is set to "value". Still, I need to tweak the code because in your case both radios should made into the submitted data considering they have different "name" fields. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
hiho Posted June 4, 2013 Share Posted June 4, 2013 (edited) Ok, thanks for the info. Can you give me an example /even if it is temporary fix/ how to change the value? I've read how the data is beign sent, but couldn't figure a way to do what I'm trying to accomplish. Edited June 4, 2013 by hiho Link to comment Share on other sites More sharing options...
trancexx Posted June 4, 2013 Author Share Posted June 4, 2013 Ok, thanks for the info. Can you give me an example /even if it is temporary fix/ how to change the value? I've read how the data is beign sent, but couldn't figure a way to do what I'm trying to accomplish. Change the form yourself. Read source, StringReplace() what you want and then fill altered form. Form-fill function can be fed with page source as string directly. Read help file remark about that. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
KaFu Posted June 4, 2013 Share Posted June 4, 2013 (edited) That's intentional. That parameter is for internal use or for use by advanced members. ...what of course made me curious ... and led to this: You are strongly discouraged to use WinHTTP in asynchronous mode with AutoIt. Edited June 4, 2013 by KaFu trancexx 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Ascend4nt Posted June 5, 2013 Share Posted June 5, 2013 ...what of course made me curious ... and led to this: You are strongly discouraged to use WinHTTP in asynchronous mode with AutoIt. Hahahah, that made me laugh. mmm, das verboten parameter.. KaFu 1 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
hiho Posted June 5, 2013 Share Posted June 5, 2013 (edited) Hi trancexx, could you tell me what am I doing wrong? This will send a request but considering the fact that the radio buttons aren't processed with the new values, I'm thinking that something ain't right. #include <Winhttp.au3> Global $hOpen, $hConnect, $sRead, $id = 12345 Global $bad[2], $good[2] $bad[0] = "name=test value=yes>" $bad[1] = "name=test checked value=no>" $good[0] = "name=test checked value=yes>" $good[1] = "name=test value=no>" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "www.site.com") StringReplace($hConnect, $bad[0], $good[0]) StringReplace($hConnect, $bad[1], $good[1]) $sRead = _WinHttpSimpleFormFill($hConnect, "/edit.php?id=" & $id, "index:0", _ ;~ my stuff here If @error Then MsgBox(64, "", "Error code :" & @error) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Edited June 5, 2013 by hiho Link to comment Share on other sites More sharing options...
trancexx Posted June 5, 2013 Author Share Posted June 5, 2013 (edited) Hi trancexx, could you tell me what am I doing wrong? This will send a request but considering the fact that the radio buttons aren't processed with the new values, I'm thinking that something ain't right. #include <Winhttp.au3> Global $hOpen, $hConnect, $sRead, $id = 12345 Global $bad[2], $good[2] $bad[0] = "name=test value=yes>" $bad[1] = "name=test checked value=no>" $good[0] = "name=test checked value=yes>" $good[1] = "name=test value=no>" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "www.site.com") StringReplace($hConnect, $bad[0], $good[0]) StringReplace($hConnect, $bad[1], $good[1]) $sRead = _WinHttpSimpleFormFill($hConnect, "/edit.php?id=" & $id, "index:0", _ ;~ my stuff here If @error Then MsgBox(64, "", "Error code :" & @error) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) It should be more like this:#include <Winhttp.au3> Global $hOpen, $hConnect, $sRead, $id = 12345 Global $bad[2], $good[2] $bad[0] = "name=test value=yes>" $bad[1] = "name=test checked value=no>" $good[0] = "name=test checked value=yes>" $good[1] = "name=test value=no>" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "www.site.com") Local $sHTML = _WinHttpSimpleRequest($hConnect, Default, "/edit.php?id=" & $id, Default, Default, "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5") ; Now you replace your shit $sHTML = StringReplace($sHTML, $bad[0], $good[0]) $sHTML = StringReplace($sHTML, $bad[1], $good[1]) ; And "action" must be full URL $sHTML = StringReplace($sHTML, "action=whatever_is_here", "action=ful_url_of_whatever_was_there") Local $hConnNew = $sHTML $sRead = _WinHttpSimpleFormFill($hConnNew, $hOpen, "index:0", _ ;~ my stuff here If @error Then MsgBox(64, "", "Error code :" & @error) _WinHttpCloseHandle($hConnNew) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Edited June 5, 2013 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now