-Ultima- Posted August 27, 2008 Share Posted August 27, 2008 (edited) Correct, that's a bug I noticed as well. I was in the process of updating these UDFs a few months ago, and managed to attain massive speed improvements over OverloadUT's version, as well as allowing custom headers (so basic HTTP auth would be possible, though an external UDF for Base64-encode the login would be needed). Unfortunately, I ran into some roadblocks (namely, how to keep connections alive in cases where the content length is unknown). This made thigs overly complicated. In the end, I opted to wrap the WinINet UDFs in AutoIt, which turned out to be much more flexible/powerful, not to mention quicker. It also supports HTTPS, has HTTP auth support built in, and basically anthing WinINet can do can now be done with AutoIt.The only potential problem here is that there's a slightly steeper learning curve, but I'd imagine someone can wrap those functions into a simpler set of APIs/UDFs not too dissimilar to OverloadUT's functions. Edited August 27, 2008 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
RyGoTypE Posted September 8, 2008 Share Posted September 8, 2008 i tried everythinkg i could think of to connect to my website and login with the specified username/password entered into the gui. still no luck connecting to my site. i also wasnt able to connect through sql either. reason i made the switch over from sql to http is safer for the website. but the only problem with http is its more unsafe for the client. cookies create an issue storing usernames and passwords in the search bar. someone with a hex editor could break down the code and get the information for the username and login of my database on the site. so either way its not looking super fantastic. but id much rather login via http. i wish i could get this working properly! http://www.shizzkabiz.com/ Link to comment Share on other sites More sharing options...
oren Posted September 18, 2008 Share Posted September 18, 2008 Wll it was hard to find this post.. I remember i once sow it... But i could not find it... i started building my script with ObjCreate("winhttp.winhttprequest.5.1") and now i've found it maybe i'll rebuild.. Anyone know whats better? ObjCreate("winhttp.winhttprequest.5.1") OR include http.au3 ? Link to comment Share on other sites More sharing options...
Mattraks Posted October 10, 2008 Share Posted October 10, 2008 Thank you for this. This really saved my life! Link to comment Share on other sites More sharing options...
Apzo Posted October 31, 2008 Share Posted October 31, 2008 Well... I've used a simple example: CODE$host = "My.server.com" $page = "directory/res.php" $vars = "cid=" & $cid & "&data=" & $data $vars = _HTTPEncodeString($vars) $socket = _HTTPConnect($host) $post = _HTTPPost($host, $page, $socket, $vars) $recv = _HTTPRead($socket, 1) _ArrayDisplay($recv) This is the error I got : CODE<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> <hr> I tried some changes to $vars (starting with a '?'), $page, but still nothing. Can someone drop here a working post example ?? Thanks in advance Apzo. All the pop3 functions.Rsync your files on your USB key (or anywhere else) Link to comment Share on other sites More sharing options...
ProgAndy Posted October 31, 2008 Share Posted October 31, 2008 You mustn't encode the whole string Just the Variables... $vars = "cid=" & _HTTPEncodeString($cid) & "&data=" & _HTTPEncodeString($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 More sharing options...
Apzo Posted October 31, 2008 Share Posted October 31, 2008 Thanks ProgAndy ! But it still doesn't work All the pop3 functions.Rsync your files on your USB key (or anywhere else) Link to comment Share on other sites More sharing options...
Kademlia Posted November 2, 2008 Share Posted November 2, 2008 Hey, just tested your code. You got bad performance for _HTTPRead As you are using TCPRecv($socket,16) on line 243. This causes very bad transfer speeds. By using 8192 or more the code works well even if you download big files. Missing: _HTTPReadToFile() ; as AutoIt will 'crash' if you download files > 20MiB anyway gread work helped me alot! Link to comment Share on other sites More sharing options...
mikeytown2 Posted November 6, 2008 Share Posted November 6, 2008 Changed _HTTPPost() so it can connect to a server that requires a user/passFunc _HTTPPost($host, $page, $socket = -1, $data = "", $user = "", $pass = "") Dim $command If $socket == -1 Then If $_HTTPLastSocket == -1 Then SetError(1) Return EndIf $socket = $_HTTPLastSocket EndIf Dim $datasize = StringLen($data) $command = "POST " & $page & " HTTP/1.1" & @CRLF $command &= "Host: " & $host & @CRLF $command &= "User-Agent: " & $_HTTPUserAgent & @CRLF $command &= "Connection: close" & @CRLF If $user <> "" And $pass <> "" Then $command &= "Authorization: Basic " & _Base64Encode($user & ":" & $pass) EndIf $command &= "Content-Type: application/x-www-form-urlencoded" & @CRLF $command &= "Content-Length: " & $datasize & @CRLF $command &= "" & @CRLF $command &= $data & @CRLF Dim $bytessent = TCPSend($socket, $command) If $bytessent == 0 Then SetExtended(@error) SetError(2) Return 0 EndIf SetError(0) Return $bytessent EndFunc ;==>_HTTPPostUsing this Base64Encode function http://www.autoitscript.com/forum/index.php?showtopic=81332 Email: POP3 & SMTP using SSL/TLS (OpenSSL)Email: IMAPEmail: Base64 & SMTP login & Send email direct to MX Server (thanks blindwig)Win: Hook Registry ChangesWin: Read/Write to Alternate Data Streams (ini example)Utility: GPS Distance Calculations, Vincenty and Haversine formulas; angles and elevationUtility: Dell Laser Printer (3000-5100) - Print LoggerUtility: Reset Router when Wireless Link FailsUtility: ImageMagick Batch jpg ProcessorVideo HCenc Batch FrontendVideo: *DEAD* YouTube Video Encoder (avs/avi to flv)Software On CD's I Like<<back|track3 Ultimate Boot CD for Windows SpinRite Ubuntu ophcrack Link to comment Share on other sites More sharing options...
Sercankd Posted November 28, 2008 Share Posted November 28, 2008 i need this udf someone please reupload it :S Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 28, 2008 Moderators Share Posted November 28, 2008 i need this udf someone please reupload it :SFirst post tells you where to get it http://www.autoitscript.com/forum/index.ph...st&p=319354 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Joennuh Posted January 11, 2009 Share Posted January 11, 2009 (edited) How to work around proxy-servers? I want my application to fetch some plain text from a PHP script, but this UDF couldn't create a socket when it has to connect through a proxy-server. Edited January 11, 2009 by Joennuh Link to comment Share on other sites More sharing options...
noidea Posted January 14, 2009 Share Posted January 14, 2009 I could really use this UDF as well, but don't see a link in the thread anywhere. Can someone repost? Link to comment Share on other sites More sharing options...
scriptguru Posted February 12, 2009 Share Posted February 12, 2009 I've added ability to send files through HTTP POST (multipart/form-data) Should I post my function here? Also I've added function that works equal to Javascript global function encodeURIComponent() Link to comment Share on other sites More sharing options...
seesoe Posted February 13, 2009 Share Posted February 13, 2009 so this can be used to read the post data of a page being sent out? Link to comment Share on other sites More sharing options...
scriptguru Posted February 13, 2009 Share Posted February 13, 2009 this can be used to upload files to server for example - to take screenshot and upload it to server Link to comment Share on other sites More sharing options...
random Posted February 13, 2009 Share Posted February 13, 2009 I've added ability to send files through HTTP POST (multipart/form-data) Should I post my function here?Yes, please!this is what i was looking when i found this topic. thank you. Link to comment Share on other sites More sharing options...
scriptguru Posted February 16, 2009 Share Posted February 16, 2009 (edited) Yes, please! this is what i was looking when i found this topic. thank you. Note that it requires Base64.au3 expandcollapse popup; =================================================================== ; _HTTPPost_files($host, $page, [$socket], [$data], [$filenames]) ; ; Executes a POST request on an open socket. ; Parameters: ; $host - IN - The hostname you want to get the page from. This should be in the format "www.google.com" or "localhost" ; $page - IN - The the file you want to get. This should always start with a slash. Examples: "/" or "/somedirectory/submitform.php" ; $socket - OPTIONAL IN - The socket opened by _HTTPConnect. If this is not supplied, the last socket opened with _HTTPConnect will be used. ; $data - array of data to send in the post request. This should first be run through _HTTPEncodeString() ; $filenames - array of paths for files to send ; Returns: ; The number of bytes sent in the request. ; Author: Val Polyakh <scriptguru@gmail.com> ; Requires: Base64.au3 ; Remarks: ; Possible @errors: ; 1 - No socket supplied and no current socket exists ; 2 - Error sending to socket. Check @extended for Windows API WSAGetError return ; =================================================================== Func _HTTPPost_files($host, $page, $socket, $data, $filenames) Local $b="---------------------------0123456789012" Local $fh,$image,$str,$picdata,$fieldname, $arr, $header Local $command If $socket == -1 Then If $_HTTPLastSocket == -1 Then SetError(1) Return EndIf $socket = $_HTTPLastSocket EndIf $command="" ;$command &= $data&@CRLF For $i=0 To (UBound($data)-1) $arr=StringSplit($data[$i],"=",2) $command &= "--"& $b &@CRLF &"Content-Disposition: form-data; name="& $arr[0] & @CRLF&@CRLF & $arr[1] &@CRLF Next For $i=0 To (UBound($filenames)-1) $arr=StringSplit($filenames[$i],"\",2);get filename $fieldname=$arr[UBound($arr)-1] $arr=StringSplit($fieldname,".",2);chop extension $fieldname=$arr[0] $fh=FileOpen($filenames[$i], 16) $image=FileRead($fh) FileClose($fh) $str=_Base64Encode($image) $command &="--"& $b _ &@CRLF&"Content-Disposition: form-data; name=" & $fieldname &"; filename="& $filenames[$i] _ &@CRLF&"Content-Type: application/upload" _ &@CRLF&"Content-Transfer-Encoding: base64"&@CRLF&@CRLF _ &$str &@CRLF Next $command &= @CRLF&"--"& $b &"--"&@CRLF Dim $datasize = StringLen($command) $header = "POST "&$page&" HTTP/1.1"&@CRLF $header &= "Host: " &$host&@CRLF $header &= "User-Agent: "&$_HTTPUserAgent&@CRLF $header &= "Connection: close"&@CRLF $header &= "Content-Type: multipart/form-data; boundary=" & $b & @CRLF $header &= "Content-Length: "&$datasize&@CRLF $header &= ""&@CRLF $command= $header & $command Dim $bytessent = TCPSend($socket, $command) If $bytessent == 0 Then SetExtended(@error) SetError(2) return 0 EndIf SetError(0) Return $bytessent EndFunc One more thing you should know is format of data you need to send. For example if your data in url-encoded format looks like xxx=1&yyy=2&zzz=3 then you should pass to this function array as follows ["xxx=1","yyy=2","zzz=3"] Edited February 16, 2009 by scriptguru Link to comment Share on other sites More sharing options...
random Posted February 19, 2009 Share Posted February 19, 2009 scriptguru, I'm trying to use your function but something doesnt work.have a look at my case:i have apache + php installed correctly (other php apps currently running on the server)a php page to receive the uploded file : uploader.phpa html page with form to test uploading through browser: form.htmlthe upload works. I find the uploaded file inside the "/upload" folder.now, i want to code an AU3 script UPLOADER.au3, to send the file without using browser.uploader.php <% $target_path = "upload/"; $target_path = $target_path . basename( $_FILES['filename']['name']); if( move_uploaded_file($_FILES['filename']['tmp_name'], $target_path) ) { echo "The file ". basename( $_FILES['filename']['name']). " has been uploaded"; echo "<p>Parameter ..... P= " . htmlspecialchars($_POST['p']); } else{ echo "There was an error uploading the file, please try again!"; } %>form.html<form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="200000000" /> P = <input type="text" name="p" value="1" /><p> Choose a file to upload: <input name="filename" type="file" /><br /> <input type="submit" value="Upload File" /> </form>the UPLOADER.au3 so far: #include <Base64.au3> #include <_HTTP.au3> #include <_HTTPPost_files.au3> #NoTrayIcon $BYTES=0 $host='localhost' $port=80 $page='/php_file_upload/uploader.php' $SOCKET = _HTTPConnect($host, $port) ; #1 dim $data[1] dim $filenames[1] $data[0] = _HTTPEncodeString( "p=1000000" ) $filenames[0] = "C:\Tools\Autoit\alex\UPLOADER\hello2.exe" ; this is a very small file 73 bytes ; being .exe has nothing to do. i tried with .zip, txt, and other types with no success $BYTES= _HTTPPost_files($host, $page, $socket, $data, $filenames ) ; #2 $closeit = _HTTPClose($socket) ; #3the script executes, ..... #1, #2, #3 return success codes , no @error, no @extendedthe $BYTES variable ends with some value > 0 but the file is not uploaded into "/uploads" Link to comment Share on other sites More sharing options...
kenunloaded Posted February 26, 2009 Share Posted February 26, 2009 scriptguru, I'm trying to use your function but something doesnt work. have a look at my case: i have apache + php installed correctly (other php apps currently running on the server) a php page to receive the uploded file : uploader.php a html page with form to test uploading through browser: form.html the upload works. I find the uploaded file inside the "/upload" folder. now, i want to code an AU3 script UPLOADER.au3, to send the file without using browser. uploader.php <% $target_path = "upload/"; $target_path = $target_path . basename( $_FILES['filename']['name']); if( move_uploaded_file($_FILES['filename']['tmp_name'], $target_path) ) { echo "The file ". basename( $_FILES['filename']['name']). " has been uploaded"; echo "<p>Parameter ..... P= " . htmlspecialchars($_POST['p']); } else{ echo "There was an error uploading the file, please try again!"; } %> form.html <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="200000000" /> P = <input type="text" name="p" value="1" /><p> Choose a file to upload: <input name="filename" type="file" /><br /> <input type="submit" value="Upload File" /> </form> the UPLOADER.au3 so far: #include <Base64.au3> #include <_HTTP.au3> #include <_HTTPPost_files.au3> #NoTrayIcon $BYTES=0 $host='localhost' $port=80 $page='/php_file_upload/uploader.php' $SOCKET = _HTTPConnect($host, $port); #1 dim $data[1] dim $filenames[1] $data[0] = _HTTPEncodeString( "p=1000000" ) $filenames[0] = "C:\Tools\Autoit\alex\UPLOADER\hello2.exe"; this is a very small file 73 bytes ; being .exe has nothing to do. i tried with .zip, txt, and other types with no success $BYTES= _HTTPPost_files($host, $page, $socket, $data, $filenames ); #2 $closeit = _HTTPClose($socket) ; #3 the script executes, ..... #1, #2, #3 return success codes , no @error, no @extended the $BYTES variable ends with some value > 0 but the file is not uploaded into "/uploads"which base64.au3 file is it. 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