• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

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
0
gregsschipper
Asked:
gregsschipper
  • 13
  • 9
1 Solution
 
Robert SchuttSoftware EngineerCommented:
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.
0
 
gregsschipperAuthor Commented:
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
0
 
Robert SchuttSoftware EngineerCommented:
I was assuming you changed the domain to a 'neutral' domain, not the actual domain?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Robert SchuttSoftware EngineerCommented:
In other words, did you change REMOTE_FILE_URL back to the url you really want to download?
0
 
gregsschipperAuthor Commented:
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
0
 
Robert SchuttSoftware EngineerCommented:
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?
0
 
gregsschipperAuthor Commented:
Thanks Robert, the old code runs without a user / password
If the new code requires it, how is that approached?
Thanks, Greg
0
 
Robert SchuttSoftware EngineerCommented:
For both objects, there's an optional 4th and 5th argument (username/password) for the .Open method.
0
 
gregsschipperAuthor Commented:
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
0
 
Robert SchuttSoftware EngineerCommented:
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

0
 
Robert SchuttSoftware EngineerCommented:
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?
0
 
gregsschipperAuthor Commented:
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
0
 
Robert SchuttSoftware EngineerCommented:
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.
0
 
gregsschipperAuthor Commented:
Tried sm.xml, 5kb.
Failed with and without user / pass.
Thanks, Greg
0
 
Robert SchuttSoftware EngineerCommented:
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.
0
 
Robert SchuttSoftware EngineerCommented:
So yes, it seems actually there's a big difference: http://support.microsoft.com/kb/289481/EN-US
0
 
Robert SchuttSoftware EngineerCommented:
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

0
 
gregsschipperAuthor Commented:
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
0
 
Robert SchuttSoftware EngineerCommented:
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.
0
 
gregsschipperAuthor Commented:
Robert, do you know anyone for hire to work on securing my Windows 2008 Server R2?
Thanks, Greg
0
 
Robert SchuttSoftware EngineerCommented:
Um, I'm in The Netherlands, so not sure if anyone I know would be able to help you (remotely perhaps) but you could try http://careers.experts-exchange.com/job-type/freelance/ or even post a question including a remark that a good answer might lead to a paid job, I think I've seen similar posts before although I'm not 100% about the rules regarding something like that. The 'freelance job exchange' would probably be a much better place for that.
0
 
gregsschipperAuthor Commented:
Very, Very Helpful!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 13
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now