Reputation: 1571
I have a scenario where I navigate to a test site, but for whatever reason (connectivity issues, etc), sometimes, the test fails because it couldn't reach the website. How do I ask for the HTTP header? I'm looking to check if it's a 404, obviously, but I haven't dealt with headers before.
Language of choice is C#, but I'm open.
Thanks for looking.
Upvotes: 0
Views: 1044
Reputation: 26874
Make an HttpRequest (I'm not showing code for brevity), then set HttpMethod = "HEAD"
and when you call GetResponse method do something like this
try{
req.GetResponse();
} catch(WebException ex) {
if (ex.Response != null)
//Server explicit problem (ie. 404)
else
//Network problem: server wasn't even hit
}
Upvotes: 1
Reputation: 662
Just try send basic HTTP request before redirecting to the page. Simply check if the webiste returns 200OK response and then redirect. Hope this example helps: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse%28v=vs.71%29.aspx
Upvotes: 0
Reputation:
FiddlerCore. It allows you to monitor/modify your application's HTTP traffic. This is if you are using a browser.
You could always send a HTTP Head request before the browser navigates if you want to check the status of the site.
Upvotes: 0