kj2 Posted June 10, 2012 Share Posted June 10, 2012 (edited) Hello, i'm trying make a http upload for a sendspace dropbox.My code is this:expandcollapse popup#include <HTTP.au3> #include <INet.au3> $Dropbox = "ifb3np" $source = _INetGetSource("http://www.sendspace.com/dropbox/"&$Dropbox) $suc = StringSplit($source, '"') For $l = 1 To $suc[0] If StringInStr($suc[$l], "dropboxupload?") Then $sUrl=StringSplit($suc[$l], '/') $host=$sUrl[3] $vars=$sUrl[4] EndIf Next ;$host = "fsxxx.sendspace.com" $port = "80" $page = "/" ;$vars = "dropboxupload?SPEED_LIMIT=0&MAX_FILE_SIZE=2096103424&UPLOAD_IDENTIFIER=xxxxxxxxxxxxxxxxxx&DESTINATION_DIR=x" $url = $page&$vars $socket = _HTTPConnect($host, $port) $get = _HTTPPost_File($host,$url,$socket,"C:\path\file.zip", "userfile",$Dropbox) $recv = _HTTPRead($socket,1) MsgBox(0, "Info", "Data received:" & @CRLF & $recv[4] & @CRLF) Func _HTTPPost_File($host, $page, $socket = -1, $file = "", $fieldname = "",$DBid = "") Dim $command If $socket == -1 Then If $_HTTPLastSocket == -1 Then SetError(1) Return EndIf $socket = $_HTTPLastSocket EndIf $contenttype = _HTTPPost_contenttype($file) ; Maybe this can be done easier/better? $boundary = "------"&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Chr(Random(Asc("A"), Asc("Z"), 3))&Chr(Random(Asc("a"), Asc("z"), 3))&Random(1, 9, 1)&Random(1, 9, 1)&Random(1, 9, 1) $fileopen = FileOpen($file, 0); Open in read only mode $fileread = FileRead($fileopen) FileClose($fileopen) $extra_commands = "--"&$boundary&@CRLF $extra_commands &= "-----------------------------"&$boundary &@CRLF $extra_commands &= 'Content-Disposition: form-data; name="hosteddropbox"'&@CRLF $extra_commands &= @CRLF $extra_commands &= $DBid $extra_commands &= "-----------------------------"&$boundary &@CRLF $extra_commands &= 'Content-Disposition: form-data; name="js_enabled"'&@CRLF $extra_commands &= @CRLF $extra_commands &= 1 $extra_commands &= "-----------------------------"&$boundary &@CRLF $extra_commands &= "Content-Disposition: form-data; name="""&$fieldname&"""; filename=""" & $file & """" &@CRLF $extra_commands &= "Content-Type: "&$contenttype&@CRLF&@CRLF $extra_commands &= $fileread&@CRLF $extra_commands &= "--"&$boundary&"--" Dim $datasize = StringLen($extra_commands) $command = "POST "&$page&" HTTP/1.1"&@CRLF $command &= "Host: " &$host&@CRLF $command &= "User-Agent: "&$_HTTPUserAgent&@CRLF $command &= "Connection: close"&@CRLF $command &= "Content-Type: multipart/form-data; boundary="&$boundary&@CRLF $command &= "Content-Length: "&$datasize&@CRLF&@CRLF $command &= $extra_commands ;debug info If FileExists("output.txt") Then FileDelete("output.txt") $file = FileOpen("output.txt", 1) FileWrite($file, $command) FileClose($file) ;end debug info Dim $bytessent = TCPSend($socket, $command) If $bytessent == 0 Then SetExtended(@error) SetError(2) return 0 EndIf SetError(0) Return $bytessent EndFunc Func _HTTPPost_contenttype($file = "") $fileextension = StringRight($file,4) ; I blieve these are the only 2 types that matter when uploading Switch $fileextension Case ".txt" $contenttype = "text/plain" Case Else $contenttype = "application/octet-stream" EndSwitch Return $contenttype EndFuncThe upload folder is this:http://www.sendspace.com/folder/nfoo8jMy problem is that when i execute the code, the uploads haven't success .may any body helpme with it?thankskjHTTP.au3 Edited June 10, 2012 by kj2 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