I'm writing code to make HttpWebRequest to website
if website is working it will return HttpStatusCode.OK
if not it will return HttpStatusCode.NotFound
My code
var url = "http://simplegames.com.ua/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Debug.WriteLine("All ok");
}
else if (response.StatusCode == HttpStatusCode.NotFound)
{
Debug.WriteLine("URL not working");
}
response.Close();
But i have errors
1) Severity Code Description Project File Line Suppression State
Error CS1061 'HttpWebRequest' does not contain a definition for
'GetResponse' and no extension method 'GetResponse' accepting a first
argument of type 'HttpWebRequest' could be found (are you missing a
using directive or an assembly
reference?) Milano C:Users
emesDocumentsGitHubMilano_pizzaMilanoMainPage.xaml.cs 50 Active
2) Severity Code Description Project File Line Suppression State
Error CS1929 'HttpWebResponse' does not contain a definition for
'Close' and the best extension method overload
'ExtensionMethods.Close(Stream)' requires a receiver of type
'Stream' Milano C:Users
emesDocumentsGitHubMilano_pizzaMilanoMainPage.xaml.cs 59 Active
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…