c# – 无法获得REST请求响应的实际错误. Fiddler向我展示了更多
发布时间:2020-12-16 00:19:51 所属栏目:百科 来源:网络整理
导读:在.NET中,我正在调用休息服务并获得异常 – 500内部服务器错误. HttpWebResponse response = request.GetResponse() as HttpWebResponse 当我在Fiddler中分析它时(在TextView中),我得到了很多关于导致错误的正确异常的细节. 在我的异常对象中,我无法在InnerE
在.NET中,我正在调用休息服务并获得异常 – 500内部服务器错误.
HttpWebResponse response = request.GetResponse() as HttpWebResponse 当我在Fiddler中分析它时(在TextView中),我得到了很多关于导致错误的正确异常的细节. 在我的异常对象中,我无法在InnerException(它为null)中获取此信息,也无法在Response对象本身中获取此信息. 有任何想法吗? 解决方法
试着看看
WebException.Response Property:
catch(WebException ex) { Console.WriteLine(ex.Message); if (ex.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status Code : {0}",((HttpWebResponse)ex.Response).StatusCode); Console.WriteLine("Status Description : {0}",((HttpWebResponse)ex.Response).StatusDescription); using (Stream responseStream = ex.Response.GetResponseStream()) { if (responseStream != null) { using (StreamReader responseReader = new StreamReader(responseStream)) { Console.WriteLine(responseReader.ReadToEnd()); } } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- vb.net 教程 3-4 窗体编程 公共控件10 TreeView
- actionscript-3 – 如何通过netConnection和netS
- 一个简单的Cairngorm框架例子
- Internationalization with the Dojo Toolkit
- c – CLOCKS_PER_SEC与std :: clock()不匹配的结
- JSONObject.fromObject(map)(JSON与JAVA数据的转
- c# – 从WinForms窗体显示WPF窗口是绝对安全的吗
- 【Cocos2d-x】Action-动作类
- 在ajax中调用java方法
- objective-c – 新手试图理解.h文件中的多个@int
热点阅读