Avatar of gregsschipper
gregsschipper
 asked on

ASP Code to Get file causes server to lockup

I use code below to GET and show links from a remote site.
Everything works well when the remote site is up.
If the remote site fails to respond, it nearly "locks up" the server running the code below.

I need a method to time out this get after 5 seconds.

Code is as follows:

REMOTE_FILE_URL="http://www.domain.com/page-links.htm"
Dim objXML, strContents, arrLines
Dim x
Set objXML=Server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET", REMOTE_FILE_URL, False
objXML.Send
strContents=objXML.ResponseText
Set objXML=Nothing
xvar=unescape(strContents)
Response.Write xvar

Many Thanks in Advance, Greg
Microsoft Server AppsScripting LanguagesWeb Languages and Standards

Avatar of undefined
Last Comment
gregsschipper

8/22/2022 - Mon
Robert Schutt

You may need to use a different object to use timeouts. Some info first:
http://msdn.microsoft.com/en-us/library/ms766431(v=vs.85).aspx 
http://msdn.microsoft.com/en-us/library/ms760403(v=vs.85).aspx 

This code waits for 1 second for each of the available timeouts, you may want to adjust to your needs.
' 1000 = 1 second
Const C_resolveTimeout = 1000
Const C_connectTimeout = 1000
Const C_sendTimeout = 1000
Const C_receiveTimeout = 1000

REMOTE_FILE_URL="http://www.domain.com/page-links.htm"
Dim objXML, strContents, arrLines
Dim xvar
Set objXML=Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") ' Microsoft.XMLHTTP
objXML.setTimeouts C_resolveTimeout, C_connectTimeout, C_sendTimeout, C_receiveTimeout
objXML.Open "GET", REMOTE_FILE_URL, False
objXML.Send
strContents=objXML.ResponseText
Set objXML=Nothing
xvar=unescape(strContents)
Response.Write xvar

Open in new window

So in your case probably only the C_connectTimeout needs to be 5000 for 5 seconds, the rest may not matter much.
gregsschipper

ASKER
Super, but I get this error:
Forbidden
You do not have permission to access this document.
Web Server at domain.com

Please advise...
Many Thanks, Greg - www.adventdigital.net
Robert Schutt

I was assuming you changed the domain to a 'neutral' domain, not the actual domain?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Robert Schutt

In other words, did you change REMOTE_FILE_URL back to the url you really want to download?
gregsschipper

ASKER
Hi Robert:
Yes, I used the actual URL for REMOTE_FILE_URL="  "
The actual domain responded back with the error:
Forbidden
You do not have permission to access this document.
Web Server at {TheActualDomain.com}

Please advise...
Thanks, Greg
Robert Schutt

Ok, any chance you haven't posted all relevant info? Like user/password needed and/or using https instead of http? I can't really think of a difference regarding permissions between the 2 pieces of code. Although there are some more properties I think you could try, I haven't investigated them all (see http://msdn.microsoft.com/en-us/library/ms754586(v=vs.85).aspx )

Is 'the actual domain' an external site or on the same server?

Also, if the retrieved url is on a site under your control could you check its error logs?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gregsschipper

ASKER
Thanks Robert, the old code runs without a user / password
If the new code requires it, how is that approached?
Thanks, Greg
Robert Schutt

For both objects, there's an optional 4th and 5th argument (username/password) for the .Open method.
gregsschipper

ASKER
Hi Robert:
I just used the FTP user / password for the site, and received the same error, denied.
objXML.Open "GET", REMOTE_FILE_URL, False,usr,psw
I defined usr and psw above this code.
Thanks, Greg
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Robert Schutt

Hmm, user/pwd for ftp are not necessarily related in any way to http access. It could be on this specific site of course but you're right, if you didn't use it in the original code it shouldn't make a difference in the new situation anyway.

Any chance you can answer the other questions:
- is 'the actual domain' an external site or on the same server?
- if the retrieved url is on a site under your control could you check its error logs?

New question: could you try a different download, for example
REMOTE_FILE_URL="http://www.schutt.nl/ee/Q_27690275/test.xml"

Open in new window

Robert Schutt

By the way, normally when any error appears that I can't explain, I often quickly search for it, not sure why I hadn't done that yet but just found this: http://support.microsoft.com/kb/291008 

It applies to Windows Authenticated sites but could it be that the standard XMLHTTP object does use that somehow by default, or could it be that the page/folder containing your original code is run under a different user account than the new code, maybe run from a test page?
gregsschipper

ASKER
Hi Robert:
1. Different Domains AND Servers at Server Beach. I have full control on both.
2. No Errors  in Error Log Regarding URL front-page-links.htm
3. The User I specified has "Full Control" on this file.

Server making the request: Windows 2008 R2
Server with the document: Linux

4. My Old code pulled in your Lorem ipsum dolor text just fine.
5. Your new code worked with REMOTE_FILE_URL="http://www.schutt.nl/ee/Q_27690275/test.xml"
Thanks, Greg
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Robert Schutt

3. The User I specified
Do you mean the FTP user? or do you mean a user running the webserver process on your linux server comparable to a specific user (other than IUSR) running an IIS process?

So no difference between the pieces of code for the xml document on my website, could you save that document (or any small xml file) to the root of your website on the linux server (assuming that's publicly available) and try again with that url? I must admit I'm now more or less just grasping at straws, not sure in which direction to think... but since a permission error is given, that seems the most likely direction, so it would be nice to be able to rule some things out.
gregsschipper

ASKER
Tried sm.xml, 5kb.
Failed with and without user / pass.
Thanks, Greg
Robert Schutt

Hmm. No go then, still no logging I assume? Is logging enabled? Anything in between that could be logging more error info?

Oh by the way I don't know what a Server Beach is, sounds like a web farm but with sea creatures ;-) But this could mean that the kb article I referred to is in fact relevant in the sense that there is a difference in accessing sites directly or through a proxy. But this is getting too deep into network admin for me I'm afraid, anybody in your company or maybe at your hosting provider that could shed a light on that? The reason I get back to that is mainly that is in fact no problem to access a file outside your own environment so it does point that way. Then again, I don't really understand what the difference with the old code is, other than the ability to set the timeouts, maybe the Server version of the object runs in a different process or something.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Robert Schutt

So yes, it seems actually there's a big difference: http://support.microsoft.com/kb/289481/EN-US
Robert Schutt

Maybe I was just too optimistic about using the latest version, could you try:
Set objXML=Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

Open in new window

gregsschipper

ASKER
Sorry, I know you've done alot of work, but the vers 3.0 fails too, with & w/o password.
Logging IS enabled, no errors on this showing up though.
Should I just award you the points anyway?
Let me know... please.
Thanks, Greg
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Robert Schutt

No, if it's not resolved you shouldn't award points. Don't feel bad about that. You can close the question choosing one of your own comments (for 0 points) or ask to have the question deleted. However, if you are planning to ask a new question then don't do the latter, you should refer to this one making it clear to other experts this road has been tried.

I do have the feeling that you didn't explore all options yet, like the proxy settings? But if that's not something you can or want to go into on that server for whatever reason, I won't make a point of it of course, that's up to you.
gregsschipper

ASKER
Robert, do you know anyone for hire to work on securing my Windows 2008 Server R2?
Thanks, Greg
ASKER CERTIFIED SOLUTION
Robert Schutt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gregsschipper

ASKER
Very, Very Helpful!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23