Introduction How to Use Buy Support More ActiveX Site Home

ActiveHTTP - Usage Example : POST


This is a typical file uploading example. The Web form has 4 fields:

username name of the user who is uploading the file
thefile path name of the file being uploaded
title title of the file
description description of the file

var hr=new ActiveXObject("ActiveHTTP.Request");

//Requst Header Items
hr.Start("POST", "/upsave.asp");
hr.AddHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*");
hr.AddHeader("Referer", "http://www.xxxxxxxx.com/upload.asp");
hr.AddHeader("Accept-Language", "en-us");
hr.AddHeader("Content-Type", "multipart/form-data; boundary=---------------------------7d52a527770268");
hr.AddHeader("Accept-Encoding", "gzip, deflate");
hr.AddHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
hr.AddHeader("Host", "www.xxxxxxxx.com");
hr.AddHeader("Connection", "Keep-Alive");
hr.AddHeader("Cache-Control", "no-cache");
hr.AddHeader("Cookie", "ASPSESSIONIDSSSQRTDB=JOBFPDNAAPOEEJPLGPNDHFBO");

//Requst Content Item 1 - username
hr.AddContentString("---------------------------7d52a527770268\r\n");
hr.AddContentString("Content-Disposition: form-data; name=\"username\"\r\n\r\n");
hr.AddContentString("Jack\r\n");

//Requst Content Item 2 - thefile
hr.AddContentString("---------------------------7d52a527770268\r\n");
hr.AddContentString("Content-Disposition: form-data; name=\"thefile\"; filename=\"e:\\temp\\mmpaper.pdf\"\r\n");
hr.AddContentString("Content-Type: application/pdf\r\n\r\n");
hr.AddContentFile("e:\\temp\\mmpaper.pdf");
hr.AddContentString("\r\n");


//Requst Content Item 3 - title
hr.AddContentString("-----------------------------7d52a527770268\r\n");
hr.AddContentString("Content-Disposition: form-data; name=\"title\"\r\n\r\n");
hr.AddContentString("Millimeter Paper\r\n");

//Content Item 4 - description
hr.AddContentString("-----------------------------7d52a527770268\r\n");
hr.AddContentString("Content-Disposition: form-data; name=\"description\"\r\n\r\n");
hr.AddContentString("Millimeter page PDF format\r\n");

//End of Requst Contents
hr.AddContentString("-----------------------------7d52a527770268--\r\n\r\n");

// Now we know the size of the content, and add it to the header
var l=hr.GetRequestContentLength();
hr.AddHeader("Content-Length", l.toString());

//Send
var r=hr.Send("www.embed.com.cn");
WScript.Echo("Return Value"+r.toString()+"\n");
if(r>0)
    {
    WScript.Echo(hr.GetResponseHeader());
    if(r==200)
    	{
	    hr.CopyResponseContent("e:\\temp\\resp.txt");
	    }
    }
hr.Reset();