Solved

ASP Code to Get file causes server to lockup

Posted on 2012-12-31
22
495 Views
Last Modified: 2013-01-04
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
Comment
Question by:gregsschipper
  • 13
  • 9
22 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38734656
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
 

Author Comment

by:gregsschipper
ID: 38736719
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38736745
I was assuming you changed the domain to a 'neutral' domain, not the actual domain?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38736783
In other words, did you change REMOTE_FILE_URL back to the url you really want to download?
0
 

Author Comment

by:gregsschipper
ID: 38736930
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38737018
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
 

Author Comment

by:gregsschipper
ID: 38737084
Thanks Robert, the old code runs without a user / password
If the new code requires it, how is that approached?
Thanks, Greg
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38737131
For both objects, there's an optional 4th and 5th argument (username/password) for the .Open method.
0
 

Author Comment

by:gregsschipper
ID: 38737168
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38737661
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38737678
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:gregsschipper
ID: 38737856
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38737949
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
 

Author Comment

by:gregsschipper
ID: 38738003
Tried sm.xml, 5kb.
Failed with and without user / pass.
Thanks, Greg
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38738088
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
 
LVL 35

Expert Comment

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

Expert Comment

by:Robert Schutt
ID: 38738144
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
 

Author Comment

by:gregsschipper
ID: 38738595
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38739297
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
 

Author Comment

by:gregsschipper
ID: 38740370
Robert, do you know anyone for hire to work on securing my Windows 2008 Server R2?
Thanks, Greg
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38740436
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
 

Author Closing Comment

by:gregsschipper
ID: 38742371
Very, Very Helpful!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Microsoft has released remote PowerShell capabilities to all commercial Office 365 customers. So you can be controlled via PowerShell and not from the Office 365 admin center Download Windows PowerShell Module for Lync Online http://www.micros…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now