Jump to content
Sign in to follow this  
sagruob

Send image through multipart/form-data POST request

Recommended Posts

sagruob
Hello, 
 
I'm trying to automate a form submission (http://prodavalnik.com/adding/). It's multipart/form-data POST request.
 
There is no problem when submitting it through POSTMAN Chrome extention. What I want is to make it fully automate so I tried to write it on Autoit. 
 I've succeded submitting the form without image data attached. Seems like encoding of the image is not as server expects. Tried different ways, but for the moment i can't upload image through this form automation. 

 

Here is a sample from the code: 

Func HttpPost($sURL, $sData = "", $sCookie = "")
Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("POST", $sURL, False)
If (@error) Then Return SetError(1, 0, 0)
 $oHTTP.SetRequestHeader("Host", "prodavalnik.com")
 $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary=----xxx")
$oHTTP.SetRequestHeader("Cookie", $sCookie)
$oHTTP.Send($sData)
If (@error) Then Return SetError(2, 0, 0)
If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0)
;Logg($oHTTP.ResponseText)
Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc

Func SendAd($multipartFileName, $imageFileName)
Local $multipartFile = FileOpen($multipartFileName, 128)
Local $imageFile = FileOpen($imageFileName, 16)
Local $postData = FileRead($multipartFile) & @CRLF & @CRLF & FileRead($imageFile) & @CRLF & "------xxx--"
HttpPost("http://prodavalnik.com/adding/", $postData, "PHPSESSID=xxx")
FileClose($multipartFile)
FileClose($imageFile)
EndFunc

SendAd("test.txt", "test.jpg")

Sorry for the awful english. 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.