c# - HTTP response code on button click -
trying build c# application (my first, apologies if stupid question)i have button on form
, when clicked check http connectivity
webserver
.
there no errors in compile returning "connection error
"
private void button3_click(object sender, eventargs e) { httpwebrequest httpreq = (httpwebrequest)webrequest.create("http://www.mysite.com"); httpreq.allowautoredirect = false; httpwebresponse httpres = (httpwebresponse)httpreq.getresponse(); if (httpres.statuscode == httpstatuscode.ok) { messagebox.show("200 ok"); } else { messagebox.show("connection error!"); } // close response. httpres.close(); }
can tell me doing wrong ?
thanks
sometimes website responses "found" , not "ok"
if (httpres.statuscode == httpstatuscode.found || httpres.statuscode == httpstatuscode.found)
[edit] threre other errors "moved permanently" decide error , not
Comments
Post a Comment