yanus69
![](http://forum.ru-board.com/board/avatars/lolly-jr.gif)
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
не работает пример отправки файлов сам разобрался Код: #include <Base64.au3> #include <HTTP.au3> ;#include <_HTTPPost_files.au3> #NoTrayIcon $BYTES = 0 $host = 'localhost' $port = 80 $page = '/3/1.php' $SOCKET = _HTTPConnect($host, $port); #1 dim $data[1] dim $filenames[1] $data[0] = _HTTPEncodeString("p=1000000") $filenames[0] = "C:\Downloads\SciTE4AutoIt3\captcha.jpg"; 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 ; =================================================================== ; _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] $fileName = $fieldname ; keep trace short original file name $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=filename; filename=" & $fileName _ & @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 ;==>_HTTPPost_files | | Всего записей: 750 | Зарегистр. 14-12-2006 | Отправлено: 11:17 17-11-2009 | Исправлено: yanus69, 12:06 17-11-2009 |
|