Jump to content

scriptguru

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by scriptguru

  1. I can post example here but your code seems to be OK - I don't know where is the trouble. Local $data="url="& euc($url) &"&title=" & euc($title) & "&tags=" & $tags & "&access=" & $access & "&body=" & euc($cbd) & "&DMSID=" & $session ;alert($data) Local $filenames Local $socket=_HTTPConnect($deepmemo_host) If $make_shot Then _ScreenCapture_Capture("screenshot.png", 0, 0, -1, -1, false) Dim $filenames[1]=["screenshot.png"] _HTTPPost_files($deepmemo_host, $add_path, $socket, StringSplit($data,"&",2), $filenames) Else _HTTPPost($deepmemo_host, $add_path, $socket, $data) EndIf Local $response=_HTTPRead($socket, 0) It is working for me. Maybe the problem in absolute/relative file local path? Also the problem maybe in server side (I'm not proficient in server-side programming so I cant give any advices). BTW now I working on proxy support for this UDF. When it will be done I'll upload whole UDF here.
  2. Note that it requires Base64.au3 ; =================================================================== ; _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 <[email protected]> ; 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"]
  3. this can be used to upload files to server for example - to take screenshot and upload it to server
  4. 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()
×
×
  • Create New...