使用webrequest跟踪错误 [英] Track error using webrequest

查看:120
本文介绍了使用webrequest跟踪错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们.

如果要在Web请求期间发生错误,我想跟踪其他网站的错误.

例如.
我正在使用HttpWebRequest从http://mywebsite.com/index.aspx页面获得响应,因此,如果在此过程中,如果mywebsite.com/index.aspx页面中发生任何错误,则应在响应中返回该错误消息. br/>
我的代码

Hi friends.

I want to track error from other website if it occurs during web request.

For example.
I am getting response from http://mywebsite.com/index.aspx page using HttpWebRequest so if during this process, if any error occur in mywebsite.com/index.aspx page then it should be returned that error message in response.

My code

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://mywebsite.com/index.aspx");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();



谢谢
Imrankhan



Thanks
Imrankhan

推荐答案

只需将其放入try-catch
如果获取对请求的响应有任何错误,它将被捕获在catch块中(尽可能多的细节!).使用它.
Just put this in a try-catch!
If there will be any error in getting response for the request asked, it will be caught in the catch block (full detail as much possible!). Use it.
try
{
   HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://mywebsite.com/index.aspx");
   HttpWebResponse res = (HttpWebResponse)req.GetResponse();
}
catch (Exception ex)
{
  //ex has all details
  //ex.Message...
}


试试吧!


Try this!


这篇关于使用webrequest跟踪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆