LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get http Status ( Response ) Code from .NET WebRequest GetResponse

Trying a get the http status code from a .NET implementation of a vi to fetch a document from a URL. I cannot seem to find a way to retrieve the response/reply code from the server (e.g. a successful retrieval is a Status=200). It appears to be stripped from the fetched header.
 
Currently, I'm assuming no error AND complete read means Status=200 but it would be helpful to know when, for example, a 404 is encountered.
 
Example code attached - fetches a document using .NET 2.0 WeRequest.
 
If the answer's obvious - my apologies as I'm a .NET newbie.
0 Kudos
Message 1 of 7
(5,474 Views)
I believe the following thread will point you in the right direction:

http://forums.ni.com/ni/board/message?board.id=170&message.id=201250&query.id=475085#M201250


Message Edited by B O B on 10-09-2007 11:48 AM

0 Kudos
Message 2 of 7
(5,458 Views)
Thanks for the link. I did run across this thread one in my earlier searches. I just posted an update to the thread showing work to-date....I just can't figure out how to get .NET to give me the Status / Reply Code. Otherwise, the posted diagram seems to work great.
0 Kudos
Message 3 of 7
(5,444 Views)
Do you mind posting either your code or a simplified version of it?  I am reinstalling the Windows updates for .NET at the moment and I can take a look into this issue once I have the class available.  Cheers!
0 Kudos
Message 4 of 7
(5,428 Views)

Here's the code (without the error code trapping). Thanks for taking a look. It's all .NET 2.0. Be sure and include the http:// prefix on the URL so the WebRequest knows what kind of request it is (https, http, ftp, etc.)

0 Kudos
Message 5 of 7
(5,420 Views)
The following page describes the .NET WebRequest Class:

http://msdn2.microsoft.com/en-us/library/system.net.webrequest(vs.80).aspx

From this page, I agree it looks like we should have access to the status description, however, you will notice if you run your code with something like 'http://www.ni.com/document.html' the LabVIEW error cluster will give you the status error code (I see "404, not found" for this example).  From the msdn page it looks like they are using the HttpWebRequest class, but I don't think this will matter.  I think the quick but nasty solution is to run through the error cluster for System.Net.WebException, or obtain the System.Net.WebException status (though LabVIEW does this for you indirectly through the error cluster).

Cheers!
0 Kudos
Message 6 of 7
(5,410 Views)

Thanks for the legwork - when I get bored Smiley Wink I'm going to try and use the info from the msdn link you provided to get the WebExceptionStatus from the Response property of the WebRequest. For now, parsing the error cluster will have to do! I'll just assume a 200 if there's no error boolean set.

0 Kudos
Message 7 of 7
(5,406 Views)