Solved

how to get http status code

Posted on 2004-05-03
16
391 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

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