Jump to content
Sign in to follow this  

http Upload file

Recommended Posts

Hi, Guru!)

Help me plz to generate post request with WinHttp 4 upload file.

My Code, dont't work (


Func Up($file)
$fileopen = FileOpen($file,16)
While 1
    $t = FileRead($fileopen, 1)
    If @error Then ExitLoop
    If $t <> 0x00 Then $fileread &= BinaryToString($t)
;~ ConsoleWrite($fileread & @LF)
$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)

$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("POST", 'http://zalil.ru/upload/')
$oHTTP.setTimeouts(5000, 5000, 15000, 15000)
$oHTTP.SetRequestHeader("Accept", "application/msword, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*")
$oHTTP.SetRequestHeader("Referer", "http://zalil.ru/")
$oHTTP.SetRequestHeader("Proxy-Connection", "Keep-alive")
$oHTTP.SetRequestHeader("Accept-Language", "ru")
$oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary="&$boundary)
$oHTTP.SetRequestHeader("Proxy-Connection", "Keep-Alive")
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")

$data="--"&$boundary& @CRLF & _
'Content-Disposition: form-data; name="file"; filename="'&$file&'"'& @CRLF & _
'Content-Type: application/x-zip-compressed'&@CRLF&@CRLF& _
$fileread & @CRLF & _
Dim $datasize = StringLen($data)

$oHTTP.SetRequestHeader("Host", "zalil.ru")
$oHTTP.SetRequestHeader("Content-Length", $datasize)
$oHTTP.SetRequestHeader("Pragma", "no-cache")

ConsoleWrite($data & @LF)
If @error Then
    ConsoleWrite('Error' & @LF)
   Return 0
$resp= $oHTTP.Responsetext
$head= $oHTTP.GetAllResponseHeaders
ConsoleWrite($head & @LF)
if StringInStr($resp,'Файл не закачался')then ConsoleWrite('NotUploaded'&@LF)
Return $resp

Read similar subjects, but a working code and has not found.

Edited by Deito

Share this post

Link to post
Share on other sites

If you are using:


then file is loaded, but the contents of the file is obtained form: "0x ..."

Surely no one is faced with downloading files via http?

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...