Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

msxml2.xmlhttp never gets past readyState 1

Status
Not open for further replies.

XgrinderX

Programmer
Mar 27, 2001
225
0
0
US
Here's a code sample - I have response.writes put in to see what's going on:

Code:
dim o
set o = server.CreateObject("MSXML2.XMLHTTP")
o.open "GET", "[URL unfurl="true"]https://www.url.com/",[/URL] true
o.setRequestHeader "header1", "value1"
o.setRequestHeader "header2", "value2"
o.onreadystatechange = GetRef("checkReadyState")
o.send

sub checkReadyState()
	response.Write("1 - " & Now() & "<br />")
	response.Write("rs = " & o.readyState & "<br />")
	if o.readyState = 4 then
		response.Write("2 - " & Now() & "<br />")
		response.Write(o.responseText)
	else
		response.Write("3 - " & Now() & "<br />")
		response.Write("rs = " & o.readyState & "<br />")
	end if
end sub 

set o = nothing

Here is the output I am getting:

1 - 11/6/2014 11:46:06 PM
rs = 1
3 - 11/6/2014 11:46:06 PM
rs = 1

Does this mean the onreadystatechange only fires once? Or is there some other problem?
 
You need to delay a bit before you terminate. The state change to 4 doesn't happen immediately. You need to hang around for at least 1 or 2 seconds.
 
I've converted your program to vbscript that you can run from a cmd prompt using

cscript //h:csrcript scriptname.vbs

Code:
dim o
set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "[URL unfurl="true"]https://www.url.com/",[/URL] true
WScript.echo "to start rs=" & o.readyState
o.setRequestHeader "header1", "value1"
o.setRequestHeader "header2", "value2"
o.onreadystatechange = GetRef("checkReadyState")
o.send
WScript.Sleep 5000
set o = nothing

sub checkReadyState()
	call WScript.echo("1 - " & Now() & "<br />")
	call WScript.echo("rs = " & o.readyState & "<br />")
	if o.readyState = 4 then
		call WScript.echo("2 - " & Now() & "<br />")
		call WScript.echo(o.responseText)
	else
		call WScript.echo("3 - " & Now() & "<br />")
		call WScript.echo("rs = " & o.readyState & "<br />")
	end if
end sub
The results are

to start rs=1
1 - 09/11/2014 06:38:11<br />
rs = 1<br />
3 - 09/11/2014 06:38:11<br />
rs = 1<br />
1 - 09/11/2014 06:38:12<br />
rs = 4<br />
2 - 09/11/2014 06:38:12<br />
 
Thanks for the reply - it still didn't work for me. Not sure what's going on. I figured out how to do it using JavaScript though, so it's all good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top