clipped from: www.tele-pro.co.uk   

HTTP Session Request

This VBScript function can be used to maintain the HTTP session state when retrieving webpages with XMLHTTP. The Cookies and Referrer are stored, and subsequent HTTP requests are re-constructed using these HTTP headers.

For example, if the first HTTP request performs a login at a website, then the second HTTP request will be performed using the same HTTP session, which has the effect of operating as the logged-in user.

This function can be used in ASP pages, VB, WSH, and in VBA code in Microsoft Office. View the code section below for more information, or view the demo.

VBScript Code

The code provides a single generic function listed below:
HTTPSessionRequest(method, url, data)

By using this function to retrieve web pages, the cookies and referrer headers are retained and the session state therefore persists between HTTP requests.

The following code demonstrates how the function can be used from within a VBS file on the desktop. Replace url1 with a login page, and url2 with a page which is protected by that login.


Option Explicit

Dim s, url1, url2
Dim data1, data2


'two requests to share the same session
url1 = "http://admin.estore-checkit.com/login/adminlogin.asp"

url2 = "http://admin.estore-checkit.com/export/orders.asp"

data1 = "uid=web&pwd=34325"
data2 = ""

'the 1st hit logs in...
s=HTTPSessionRequest("POST", url1, data1)
MsgBox s

'subsequent hits use the same session
s=HTTPSessionRequest("GET", url2, data2)
MsgBox s


Purchasing Options

The HTTP Session Request function is available as a VBScript function that can be used in your ASP pages and VB code. Click the button below to purchase:

HTTP Session Request: £20