Search code examples
c#asp.nethttphttpwebrequesthttpwebresponse

whille checking http status code getting error saying - The remote server returned an error: (503) Server Unavailable


i want to insert url/link if its a valid url. for that im checking status code . but for some links im gettig this error even though its a valid link

    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(LinkCheck);
    myHttpWebRequest.Timeout = 150000;
    myHttpWebRequest.Method = "HEAD";
    myHttpWebRequest.UserAgent = "Foo";
    myHttpWebRequest.Accept = "*/*";
    myHttpWebRequest.AllowAutoRedirect = false;
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();//getting error here
    MyStatusCode = ((int)myHttpWebResponse.StatusCode);
    myHttpWebResponse.Close();

input- http://www.jabong.com/men/ output should come = 200 but its throwing error


Solution

  • The server you are making a request to doesn't seem to support the HEAD HTTP verb. Change your request to type to GET and it'll work just fine:

    myHttpWebRequest.Method = "GET";