Post binary data to URL from WSH/ASP/VBA/VBScript.
ActiveX RegEdit.   ActiveX User account Manager   Pure-ASP Upload
Export MDB/DBF from ASP   Active LogFile   WebChecker   ActiveX/ASP Multi Dictionary object
 See 
 also 
 IISTracer, real-time IIS monitor and logging tool.
 Huge ASP file upload with progress bar. 



Do you like this article?
Please, rate it
and write review!
Rated:
by Aspin.com users
What do you think?
 Top messages
 22.3.2003 19:18:41 
 Read and write SQL image data, store binary file to sql table. (nbsp;WSHDatabaseConversionVBScript)
 22.3.2003 17:07:03 
 Work with binary files in VBSscript - read and write local and remote files (nbsp;WSHFile & data transferFunctionsVBScript)
 8.1.2001 9:55:13 
 Replace one string to another in a text file (nbsp;WSHConversionVBScript)

 Post binary data to URL from WSH/ASP/VBA/VBScript. 

 Areas>Languages>VBScript
 Areas>ASP / ASP.Net>File & data transfer
 Areas>WSH

      This article was created as appendix for Upload file using IE+ADO without user interaction - VBS. The "Upload file" article lets you build multipart/form-data document from source file. You can send the binary document to any server using several ways.

1. Internet explorer.

      "Upload file" article contains function IEPostBinaryRequest, which uses most common http object - Internet explorer. The object has one great characteristic - you can find it on any Windows computer, so you can use the code on webhosting computers, without installing of another software. But the object is NOT optimal to use it in such tasks. Positives, negatives:
+ Present on each Windows computer
+ When debugging, you can uncomment "Visible" line and see results of upload script directly.
- InternetExplorer.Application does not have a method, which lets you wait to end of request. You must do "do-loop" to wait.
- IE takes more memory than other methods
- IE Uses WinInet API, which is not suitable for use in ASP applications (You can run maximum of two instances per server in destination URL)

'sends multipart/form-data To the URL using IE
'FormData - binary (VT_UI1 | VT_ARRAY) multipart form data
Function IEPostBinaryRequest(URL, FormData, Boundary)
  'Create InternetExplorer
  Dim IE: Set IE = CreateObject("InternetExplorer.Application")
  
  'You can uncoment Next line To see form results
  'IE.Visible = True
   
  'Send the form data To URL As POST binary request
  IE.Navigate URL, , , FormData, _
    "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf

  Do While IE.Busy
    Wait 1, "Upload To " & URL
  Loop
  
  'Get a result of the script which has received upload
  On Error Resume Next
  IEPostBinaryRequest = IE.Document.Body.innerHTML
  IE.Quit
End Function

Sub Wait(Seconds, Message)
  On Error Resume Next
  Dim Shell
  If IsEmpty(Shell) Then Set Shell = CreateObject("wscript.shell")
  Shell.Popup Message, Seconds, "", 64
End Sub

2. http request object.

      Other free method to send binary data is "http request" object from MS. As usuall in MS, there are several versions of http request objects.
1. XMLHTTP. First http request object from MS, designed to work with VBS/ASP/WSH. This object uses WinInet API (which is not suitable for use in ASP applications, see IE)
2. ServerXMLHTTP. This object was created because of problems with XMLHTTP in server applications. It contains its own http engine, which is safe to use in server applications. The http engine has some small limitations (I think it does not enable client certificates, etc.), but the limitations has probably no impact to usual demands.
You can find XMLHTTP/ServerXMLHTTP at http://msdn.microsoft.com in MS XML package as free download.
3. WinHTTP object. Similar as ServerXMLHTTP You can find the object at http://msdn.microsoft.com, search for WinHTTP.
My recomendation - use this object, if you can install it. MSXML 4.0 package uses this library also (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/sdk_dependencies_9po5.asp)

      These three objects has almost the same OLE interface, so you can use the same source code:

'sends multipart/form-data To the URL using WinHttprequest/XMLHTTP
'FormData - binary (VT_UI1 | VT_ARRAY) multipart form data
Function WinHTTPPostRequest(URL, FormData, Boundary)
  Dim http 'As New MSXML2.XMLHTTP
  
  'Create XMLHTTP/ServerXMLHTTP/WinHttprequest object
  'You can use any of these three objects.
  Set http = CreateObject("WinHttp.WinHttprequest.5")
  'Set http = CreateObject("MSXML2.XMLHTTP")
  'Set http = CreateObject("MSXML2.ServerXMLHTTP")
  
  'Open URL As POST request
  http.Open "POST", URL, False
  
  'Set Content-Type header
  http.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + Boundary
  
  'Send the form data To URL As POST binary request
  http.send FormData
  
  'Get a result of the script which has received upload
  WinHTTPPostRequest = http.responseText
End Function
 
 

See also for 'Post binary data to URL from WSH/ASP/VBA/VBScript.' article:

     Work with binary files in VBSscript - read and write local and remote files Reading and writting binary and text files is a first task you will need to solve in server-side ASP. This article contains several VBS functions which let's you store data to local disk and read local or remote (http) files.
     Automatic file upload using IE+ADO without user interaction - VBSscript Lets you upload file from a client to www server over http connection using vbs, IE and ADODB. The file is sent as a result of type=file form field encoded multipart/form-data.

If you like this page, please include next link on your pages:
<A
 Href="http://www.motobit.com/tips/detpg_post-binary-data-url/"
 Title="Two methods to POST binary or
  string data to external URL
  and read results sent from
  a script on the URL."
>Post binary data to URL from WSH/ASP/VBA/VBScript.</A>

     IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).      ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.
     Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.      ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.
     ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.      Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.
     Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).      ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).
     WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.      HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.

© 1996 – 2012 Antonin Foller, PSTRUH Software, e-mail help@pstruh.cz
Motobit.com