Jump to content

XMLHTTP Object to submit form with file


Simucal
 Share

Recommended Posts

I'm attempting to write a script to post images to www.imageshack.us . I have applied for and received a developer key from them which gives me permission to use their XML API.

While just playing around with idea of submitting images to their website through a script I used the IE udf's to come up with a quick hack:

#include <IE.au3>
Global $sFilename = "C:\test.jpg"
$oIE = _IECreate("www.imageshack.us")
$oForm = _IEFormGetObjByName($oIE, "upform")
$oInputFile = _IEFormElementGetObjByName($oForm, "fileupload")
$oSubmit = _IEFormElementGetObjByName($oForm, "butan")
_IEAction($oInputFile, "focus")
Send($sFilename)
_IEAction($oSubmit, "click")oÝ÷ Øz0z÷«»aȬoø¡£0Èm¢Ë+b¨°(ºWeG­¢ë¶8Êç-1/,>Ú¢{-®ç-j,¶g¬±¨Â+a¶¦è¦¸µè¦jWÛ.nh­ÔáËzk%Gç!ÞzW j{[­í¢g®ùbþéRyªÜ)àjº.Ú'¶§z×è®)ߢ¹¶*'¢{ays4Ï¡¸ÞrÒ!j÷¦i×­+&y¨­«mzjmjÜ!jÒ7ökkÊ)à¶hjëh×6Func _UploadImage($sFilepath) 
$oXMLHTTP = ObjCreate("MSXML2.XMLHTTP")
$oXMLDOC = ObjCreate("MSXML.DOMDocument")
$oXMLHTTP.Open("POST", "http://www.imageshack.us/index.php", "false") ; Set http verb to post, url, and asynchronous mode to false
$oXMLHTTP.setRequestHeader("Content-Type", "multipart/form-data;")
;some how include image binary data in post here ?
$oXMLHTTP.Send("fileupload="&$sFilePath&'&xml="yes"') ; I dont believe I need to submit the filepath, but the actual file data itself
$sData = $oXMLDoc.load($oXMLHTTP.responseXML.xml)
If Not $sData Then
    MsgBox(0, "Error", "Error Loading XML from HTTP")
EndIf
EndFunc

I knew this wouldn't work even when I wrote it, but I wanted to show I've made some attempt. I need to some how submit the binary data of the image in my post request. If you go to the developer website of imageshack it says this:

Regular Uploading

Send the following variables via POST to http://www.imageshack.us/index.php

* fileupload; (the image)

* xml = "yes"; (specifies the return of XML)

* cookie; (registration code, optional)

Assuming the upload completes without problems, the xml data may be manipulated as necessary. To show the user the results of his or her upload, redirect the user to <done_page>.

Website I have found that seem somewhat related to this topic:

Post binary data to website using HTTP Post

Wikipedia XMLHTTPRequest

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

I just saw the COM support section, perhaps this should of gone there.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Ok.. so I'm making a little progress. I have since figured out how to stream the binary data of the image in the post message (using the ADODB object). However, I am not exactly sure how to pass the variables that imageshack mentioned they needed (fileupload and xml="yes").

Can ANYONE look at what I've done here and give me some pointers?

Func _UploadImage($sFilepath)
$oXMLHTTP = ObjCreate("MSXML2.XMLHTTP")
$oXMLDOC = ObjCreate("MSXML.DOMDocument") ; for later reading the XML data from the upload
$oAdoStream = ObjCreate("ADODB.Stream") ; for streaming the image in the post message
$oAdoStream.Mode = 3  ; Set read/write
$oAdoStream.Type = 1 ; Type Binary
$oAdoStream.Open()
$oAdoStream.LoadFromFile($sFilePath)
$oXMLHTTP.Open("POST", 'http://www.imageshack.us/index.php', "false") ; Set http verb to post, url, and asynchronous mode to false
$oXMLHTTP.setRequestHeader("Content-Type", "multipart/form-data;")
;$oXMLHTTP.setRequestHeader("Content-Length", $oAdoStream.Size)
$oXMLHTTP.Send('fileupload="'&$oAdoStream.Read($oAdoStream.Size)&'"&xml="yes"') ; Pretty sure this is how I should stream the data of the image, but am I'm not passing the variables right.
ConsoleWrite("Response Text: "&$oXMLHTTP.responseText)
$sData = $oXMLDoc.load($oXMLHTTP.responseXML.xml)
If Not $sData Then
    MsgBox(0, "Error", "Error Loading XML from HTTP")
EndIf
EndFunc
Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

  • 1 month later...

Little Tips :

Don't use "False" to Open an URL for an async mode, but -1 , like this :

$oXMLHTTP.Open("POST", 'http://www.imageshack.us/index.php', -1) ; :shocked: it works as async request, so you could use AdlibEnable to update a progressbar when receiving data

instead of :

$oXMLHTTP.Open("POST", 'http://www.imageshack.us/index.php', "false") ; it don't work as async request :(

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...