Hi
HttpWebRequest.GetResponse newer returns if calling a nonexistent IP.
It frezes even if timeout's is lowered.
Per
StreamReader stream = null;
string result = string.Empty;
WebResponse webResponse = null;
try {
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create("http://192.168.1.221/values.html");
//webReq.Timeout = 10000;
//webReq.ReadWriteTimeout = 500;
webResponse = webReq.GetResponse();// never returns
if (webResponse.ContentLength > 0) {
stream = new StreamReader(webResponse.GetResponseStream());
result = stream.ReadToEnd();
if (result != null && result.Length > 10) {
webReqFejl = false;
}
else {
webReqFejl = true;
}
//Debug.Print("Data fra pillefyr hentet");
}
else {
webReqFejl = true;
}
}
catch (Exception ex) {
webReqFejl = true;
#if DEBUG
Debug.Print(ex.Message);
#endif
}
finally {
if (stream != null) {
stream.Close();
}
if (webResponse != null) {
webResponse.Close();
}
}
return result;