Jump to content

WinHttp.WinHttpRequest.5.1 - POST binary file


Recommended Posts

Hi all,

I'm trying to post a binary file using WinHttp.WinHttpRequest.5.1 and the POST method.

CODE

$sUrl = "http://192.168.0.1/cgi-bin/upload_file.cgi"

$PostData="executable.exe"

ConsoleWrite($PostData)

$oHttpRequest = ObjCreate("WinHttp.WinHttpRequest.5.1")

$oHttpRequest.Open ("POST", $sUrl, False)

$oHttpRequest.setRequestHeader("Connection", "Keep-Alive")

$oHttpRequest.setRequestHeader("Referer", "http://192.168.0.1/cgi-bin/upload_file.cgi")

$oHttpRequest.Send ($PostData)

Since it's not working, I sniffed the traffic and got the following message by the time I was uploading the file. Can anybody point me to the documentation where I can see what this boundary variable should contain?

HTTP Protocol

- The multipart dissector could not find the required boundary parameter

Thanks

Edited by Total_newbie
Link to comment
Share on other sites

Looks like the error might be similar to this: WireShark Wiki: MIME multipart (mime_multipart)

That looks like a setting in WireShark to know how to break down the MIME packets. Specifically, how to know what delimits the parts of the MIME block of data.

:shocked:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Not sure, but you might try changing this line:

$PostData=FileRead("executable.exe")

Here is the documentation for the WinHTTP Request object:

http://msdn2.microsoft.com/en-us/library/aa384106.aspx

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

You're missing the 'Content-Type' RequestHeader that tells the server how to parse what you are posting...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

You're missing the 'Content-Type' RequestHeader that tells the server how to parse what you are posting...

Dale

Hi Dale, you are right. I added the following line $oHttpRequest.setRequestHeader ("Content-Type", "multipart/form-data") and now it's complaining about the boundary parameter which should look like this ";boundary=---------------------------7d71f2d701e2". Based on some documentation that I read this information is generated automatically as well as the "Content-Lenght" parameter. Now I'm trying to find out how do I generate and pass that to my script. Any clue?
Link to comment
Share on other sites

You're missing the 'Content-Type' RequestHeader that tells the server how to parse what you are posting...

Dale

Hi Dale, I decide to play a little bit with IE.au3 and was trying the example 5 of the help. However I cannot submit the form after insertig the filename in the form. Any clue?

CODE
#include <IE.au3>

$oIE = _IECreate ("http://10.0.0.108/cgi-bin/upload_form.cgi")

$oForm = _IEFormGetCollection ($oIE, 0)

$oInputFile = _IEFormElementGetObjByName ($oForm, "x_filename")

_IEAction($oInputFile, "focus")

$hIE = _IEPropertyGet($oIE, "hwnd")

ControlSend($hIE, "", "Internet Explorer_Server1", "example.au3")

$osubmit = _IEFormElementGetObjByName ($oForm, "Submit")

_IEAction($osubmit, "click")

_IEAction($oIE, "visible")

Link to comment
Share on other sites

Hopefully you are running this with Tools -> Go in SciTe... do you get any messages in the console?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...