We help IT Professionals succeed at work.

XMLHTTP Timeout and ServerXMLHTTP receiving javascript error

TSPatrick
TSPatrick asked
on
Medium Priority
6,904 Views
Last Modified: 2012-05-06
Ok guys and gals here is my problem.

I am trying to send 2 POST and 1 GET to a remote server via my .vbs file script from my Windows 2003 server.  I know that I should be using the ServerXMLHTTP version but I can not get it to work properly and the XMLHTTP version just timesout.  When I use the XMLHTTP version it timesout on the line below.

objXMLHTTP3.Open "GET", "http://***.*********.com/lbs/AccessReport?Style=CSV&SID=" & strSID, false
objXMLHTTP3.Send  

When I use the ServerXMLHTTP version the remote server never let's me past the first POST.  I receive the following error from the remote server.
ERROR: Your browser's JavaScript capability seems to be disabled.
* So this never let's me past the login page.  :(

Below I have included the code that is requesting the 2 POST and 1 GET.  I have x'ed out the domain for privacy.  There may also be some variables that are not declared in the code provided but the are named elsewhere in the code.


Set objXMLHTTP = CreateObject("Msxml2.XMLHTTP.6.0")
 ' timeouts: resolve, connect, send, receive - in milliseconds
'objXMLHTTP.setTimeouts 10000, 60000, 30000, 30000
 
' Login
objXMLHTTP.Open "POST", "http://***.********.com/lbs/OnLogin", False
objXMLHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"
objXMLHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
objXMLHTTP.Send "irtUserName=" & strUsername & "&irtUserPassword=" & strPassword
 
' Pause until page is ready
While objXMLHTTP.status <> 200 And objXMLHTTP.readyState <> 4
    objXMLHTTP.waitForResponse 1000 
Wend
Set objXMLHTTP = Nothing
 
' Set Permisson
Set objXMLHTTP2 = CreateObject("Msxml2.XMLHTTP.6.0")
objXMLHTTP2.Open "POST", "http://***.**********.com/lbs/OnSelectPermission", False
objXMLHTTP2.setRequestHeader "Referer", "http://***.**********.com/lbs/OnLogin" 
objXMLHTTP2.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"
objXMLHTTP2.setRequestHeader "Host", "************.com"
objXMLHTTP2.setRequestHeader "Connection", "Keep-Alive" 
objXMLHTTP2.setRequestHeader "Cache-Control", "no-cache"
objXMLHTTP2.setRequestHeader "Cookie", "x=y" 
objXMLHTTP2.Send "irsPermissionID=" & "AG" & strAgentID & "*AGENT"
 
' Pause until page is ready
While objXMLHTTP2.status <> 200 And objXMLHTTP2.readyState <> 4
    objXMLHTTP2.waitForResponse 1000 
Wend
Set objXMLHTTP2 = Nothing
 
' Get CSV File 
Set objXMLHTTP3 = CreateObject("Msxml2.XMLHTTP.6.0")
objXMLHTTP3.Open "GET", "http://***.**********.com/lbs/AccessReport?Style=CSV&SID=" & strSentriLock_SID, false 
objXMLHTTP3.Send  
 
' Pause until page is ready
While objXMLHTTP3.status <> 200 And objXMLHTTP3.readyState <> 4
    objXMLHTTP3.waitForResponse 1000 
Wend
 
CSV_Text = objXMLHTTP3.responseText
Set objXMLHTTP3 = Nothing

Open in new window

Comment
Watch Question

Commented:
> ERROR: Your browser's JavaScript capability seems to be disabled.

Have you tried visiting the site with your browser and with javascript disabled? Did you find anyway to login?

Author

Commented:
Should I try this from the browser on the server?

Commented:
It does not matter. It seems clear that the site you want to visit with the ServerXMLHTTP requires javascript to log in. Because ServerXMLHTTP does not support javascript, you are faced with a problem. Maybe you can work around it if the site lets you login without javascript. So my suggestion is just that: try to login on the site with a browser with javascript disabled.

Author

Commented:
OK. I visit the site from my server with javascript disabled and was able to successfully login.  Wierd.  Becasue the file that is downlloaded with GET request is the login page and the javascript error.  Not sure what to do now.  Any ideas?

Commented:
Somewhere along the line you should have seen this error in your browser:
"ERROR: Your browser's JavaScript capability seems to be disabled. "

If not, maybe the browser responded to a metatag redirect.
But what you need to do is find the "action" of the login form, because that is where the username/password are send to. Also make sure that you know if it is POST or GET.

Also, and this is important, if you need to get behind a login with ServerXMLHTTP, then it is essential that you use the same ServerXMLHTTP object for login and then for getting to the other pages. The way you are doing it in your code (each time with a new object) is like logging, closing your browser and then expect to still be logged in after restarting the browser.


Author

Commented:
I have logged in successfully with just XMLHTTP but it occasionally hangs un the GET request (Downloading a CSV file) but when I use the ServerXMLHTTP it send me back the content of the login page with the javascript error.

Commented:
below is something that i implemented some time ago.

Customise it the way you want

 hope it helps
Function getField(strXPath, objDoc)
	Dim objNode
	Set objNode = objDoc.documentElement.selectSingleNode(strXPath)
 
	On Error Resume Next
	'clear the Err object
	Err.Clear
	'The following statement might cause an exception
	getField = objNode.Text
 
	'Check if an exception was raised
	If Err.Number >  0 then
	getField = ""
	End If
 
End Function
 
Sub connect()
'declaration	
	
	pxPayUrl    = "URL"
	pxPayUser  = "ID"
	pxPayKey = "Password"
 
 
	xmlRequest = "<ProcessResponse>" &_
	"<PxPayUserId>" & pxPayUser & "</PxPayUserId>" &_
	"<PxPayKey>" & pxPayKey & "</PxPayKey>" &_
	"<Response>" & result & "</Response>" &_
	"</ProcessResponse>"
 
 
	Set objSrvHTTP = server.Createobject("MSXML2.ServerXMLHTTP")
 
	objSrvHTTP.open "POST",pxPayUrl,False
	objSrvHTTP.send xmlRequest
	strReturn = objSrvHTTP.responseText
	
	Set xmlDoc = server.CreateObject ("Msxml2.FreeThreadedDOMDocument.3.0")
	xmlDoc.async = false
	xmlDoc.loadXML(strReturn)
	
'extracting codes should go here	
	
End Sub

Open in new window

OK, nothing is working. It hangs (timesout) up on the following line.

objXMLHTTP.Open "GET", "http://***.*******.com/lbs/AccessReport?Style=CSV&SID=" & strSID, false
objXMLHTTP.Send  

Below is the code.  Please help.
Set objXMLHTTP = CreateObject("Msxml2.SERVERXMLHTTP.6.0")
 ' timeouts: resolve, connect, send, receive - in milliseconds
'objXMLHTTP.setTimeouts 10000, 60000, 30000, 30000
 
 
' Login
objXMLHTTP.Open "POST", "http://***.*******.com/lbs/OnLogin", False
objXMLHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"
objXMLHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
objXMLHTTP.Send "irtUserName=" & strUsername & "&irtUserPassword=" & strPassword
 
' Pause until page is ready
While objXMLHTTP.status <> 200 And objXMLHTTP.readyState <> 4
    objXMLHTTP.waitForResponse 1000 
Wend
If strAgentID <> "" Then
' Set Permisson
objXMLHTTP.Open "POST", "http://***.*******.com/lbs/OnSelectPermission", False
objXMLHTTP.setRequestHeader "Referer", "http://***.*******.com/lbs/OnLogin" 
objXMLHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"
objXMLHTTP.setRequestHeader "Host", "sentrilock.com"
objXMLHTTP.setRequestHeader "Connection", "Keep-Alive" 
objXMLHTTP.setRequestHeader "Cache-Control", "no-cache"
objXMLHTTP.setRequestHeader "Cookie", "x=y" 
objXMLHTTP.Send "irsPermissionID=" & "AG" & strAgentID & "*AGENT"
' Pause until page is ready
While objXMLHTTP.status <> 200 And objXMLHTTP.readyState <> 4
    objXMLHTTP.waitForResponse 1000 
Wend
End If
 
' Get CSV File 
objXMLHTTP.Open "GET", "http://***.*******.com/lbs/AccessReport?Style=CSV&SID=" & strSID, false 
objXMLHTTP.Send  
 
' Pause until page is ready
While objXMLHTTP.status <> 200 And objXMLHTTP.readyState <> 4
    objXMLHTTP.waitForResponse 1000 
Wend
CSV_Text = objXMLHTTP.responseText
Set objXMLHTTP = Nothing

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.