public static HttpResponseDTO GetResponse(Uri url, int timeoutInSeconds) { HttpResponseDTO dto = new HttpResponseDTO(); try { HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.Proxy = new WebProxy(); request.Method = "HEAD"; request.AllowAutoRedirect = true; request.Timeout = timeoutInSeconds * 1000; request.ServicePoint.BindIPEndPointDelegate = delegate(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { if (remoteEndPoint != null) { dto.ResponseIP = remoteEndPoint.Address.ToString(); } return(null); }; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { dto.StatusCode = (int)response.StatusCode; dto.ResponseUri = response.ResponseUri; dto.ContentLength = response.ContentLength; dto.ContentType = response.ContentType; dto.TimeStamp = DateTime.UtcNow; } } catch (Exception) { } return(dto); }
public static HttpResponseDTO GetResponse(Uri url, int timeoutInSeconds) { HttpResponseDTO dto = new HttpResponseDTO(); try { HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.Proxy = new WebProxy(); request.Method = "HEAD"; request.AllowAutoRedirect = true; request.Timeout = timeoutInSeconds * 1000; request.ServicePoint.BindIPEndPointDelegate = delegate(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { if (remoteEndPoint != null) { dto.ResponseIP = remoteEndPoint.Address.ToString(); } return null; }; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { dto.StatusCode = (int)response.StatusCode; dto.ResponseUri = response.ResponseUri; dto.ContentLength = response.ContentLength; dto.ContentType = response.ContentType; dto.TimeStamp = DateTime.UtcNow; } } catch (Exception) { } return dto; }