Solved

how to get http status code

Posted on 2004-05-03
16
427 Views
Last Modified: 2012-06-21
Hi! Does anybody here know how to get http status code using ASP?  I tried running the code from http://www.asp101.com/samples/http.asp
but I didn't see any result. It didn't even said that there's an error.

Can someone please help me? Thanks!
0
Comment
Question by:lian_al
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
16 Comments
 
LVL 21

Expert Comment

by:ap_sajith
ID: 10975810
Try this sample...

<%
  'Declare the variables, and set the value of the variable url as
  'the full URL of the requested page.
  Dim xml, strData, url
  url = "http://www.someserver.com/somepage.asp"

  'Next, create an instance of the MS XMLhttp component.
  'old version, unstable server side performance so upgrade if you can
  ' *** OLD *** Set xml = Server.CreateObject("Microsoft.XMLHTTP")
      
  'new version, better server side performance
  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  'Now open the connection, and send the request to the remote server. You
  'need to set the optional Async parameter to True on the open method for
  'this script to work. Otherwise, the waitForResponse method used
  'below will have no effect.
  xml.Open "GET", url, true   ' the True specifies an asynchronous request
  Call xml.Send()

 'Turn off error handling
  On Error Resume Next
 
  'Wait for up to 3 seconds if we've not gotten the data yet
  If xml.readyState <> 4 then
    xml.waitForResponse 3
  End If

  'Did an error occur?  If so, use a default value for our data
  If Err.Number <> 0 then
    strData = "some default text..."
  Else
    If (xml.readyState <> 4) Or (xml.Status <> 200) Then
      'Abort the XMLHttp request
      xml.Abort
           
        strData = "Problem communicating with remote server..."
    Else
      strData = xml.ResponseText
    End If
  End If
%>

Cheers!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 10975842
as for the ASP 101 sample, are you just getting a blank screen?. Make sure that you are Passing the correct URL.

Cheers!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 10975921
Here is a sample working code...

<%
  'Declare the variables, and set the value of the variable url as
  'the full URL of the requested page.
  Dim xml, strData, url
  url = "http://localhost/test.asp"

  'Next, create an instance of the MS XMLhttp component.
  'old version, unstable server side performance so upgrade if you can
  ' *** OLD *** Set xml = Server.CreateObject("Microsoft.XMLHTTP")
     
  'new version, better server side performance
  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  'Now open the connection, and send the request to the remote server. You
  'need to set the optional Async parameter to True on the open method for
  'this script to work. Otherwise, the waitForResponse method used
  'below will have no effect.
  xml.Open "GET", url, true   ' the True specifies an asynchronous request
  Call xml.Send()

 'Turn off error handling
  On Error Resume Next
 
  'Wait for up to 3 seconds if we've not gotten the data yet
  If xml.readyState <> 4 then
    xml.waitForResponse 3
  End If

  'Did an error occur?  If so, use a default value for our data
  If Err.Number <> 0 then
    strData = "some default text..."
  Else
    If (xml.readyState <> 4) Then
      'Abort the XMLHttp request
      xml.Abort
           
       strData = "Problem communicating with remote server..."
    Else
      strData = xml.Status & "<br><br><br>" & xml.ResponseText
    End If
  End If

  Response.write strData
%>

Change the URL parameter to the page you are trying to access. Also, make sure that the code works for pages within your network before trying pages on the internaet. The XMLHTTP access to the internet from the server could be blocked.

Cheers!!
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:lian_al
ID: 10975961
I tried the code you gave me but I still got a blank screen. Do I have to install a component first or something? I'm using Win2000 Service Pack 3. I've already downloaded and installed MsXML4 sp2 from Microsoft.

Thanks ap_sajith!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 10976598
Are you able to run other asp pages?. It wouldnt be a problem with the component not being installed because it should have thrown an error. Try removing the On error resume next statement.

Also, try a step by step analysis..

eg:

<%
  'Declare the variables, and set the value of the variable url as
  'the full URL of the requested page.
  Dim xml, strData, url
  url = "http://localhost/test.asp"

  'Next, create an instance of the MS XMLhttp component.
  'old version, unstable server side performance so upgrade if you can
  ' *** OLD *** Set xml = Server.CreateObject("Microsoft.XMLHTTP")
     
  'new version, better server side performance
  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
If isIbject(Xml) Then
Response.write "Object Created"
Response.end
End If

etc.

Post the exact same code of the page you were trying to execute.

Cheers!!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10977691
>>I tried the code you gave me but I still got a blank screen. <<
That is because it is XML.  Try doing View Source and you will see it there.
0
 

Author Comment

by:lian_al
ID: 10982901
I tried the code you gave me..the object was created. But I still can't get it to display the status. I even tried viewing the source, but the status code could not be found there also.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10983107
>>I even tried viewing the source<<
Right the source should have shown you just the XML.

>>but the status code could not be found there also.<<
You can use:
Response.Write xml.Status

After the using the Send method.
0
 

Author Comment

by:lian_al
ID: 10983156
This is my code..

<%
  Dim xml, strData, url
  url = "http://www.google.com"

  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
  xml.Open "GET", url, false   ' the True specifies an asynchronous request
  Call xml.Send()

  response.write xml.status

%>

When I viewed the source, here's the output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

How come the status still isn't displayed? What else should I do? Thanks!!!
0
 

Author Comment

by:lian_al
ID: 10983862
Are there other ways on how I can get the status code? I've been searching through the Internet for days now..and upto now I still don't have any solution
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 125 total points
ID: 10985114
Create a new page called test.asp in the same folder you are running this asp page from. . Add the following code in the page.

<%=Now%>

Now change your code in the page to check status to..

<%
  Dim xml, strData, url
  url = "http://localhost/test.asp"
' ** You Can type in the actual URL if it is different from the one specified above.
' ** WE CAN TRY CONNECTING TO PAGES IN THE INTERNET LATER **

  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
  xml.Open "GET", url, false   ' the True specifies an asynchronous request
  Call xml.Send()
  response.write xml.status
%>

Cheers!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 11020824
Any updates?

Cheers!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 11179292
Hi,
Any Updates?. Do you need any further assistance with this?. Please close this question if no further assistance is needed.
If you need help closing this question, please refer to http://www.experts-exchange.com/help.jsp#hs5 on how to close a question.

Cheers!!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problems using Provider=OraOLEDB.Oracle via VBScript/Classic ASP 5 129
Syntax for query to update table 2 55
Button on Table, name table1 not working 4 43
ASP AND XML 3 41
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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