httpWebRequest - 获取错误内容 [英] httpWebRequest - get error content
问题描述
throw new WebFaultException< String>(bla bla bla,
HttpStatusCode.HttpVersionNotSupported);
但是当我尝试在
$ b $中获取错误内容b
var r =(HttpWebResponse)(request.GetResponse());
if(r.StatusCode!= HttpStatusCode.OK){...
问题GetResponse()抛出WebException错误。我不可能得到bla bla bla的文字。如何获取此文本? Web异常包含状态代码HttpVersionNotSupported,但不包含文本bla bla bla的属性。我作为WebFaultException的第一个参数发送的数据在哪里?
尝试使用 HttpWebResponse.GetResponseStream 访问响应内容的方法。链接中的示例代码应该显示如何读取和清理流。
I throw an error in my REST service like:
throw new WebFaultException<String>("bla bla bla",
HttpStatusCode.HttpVersionNotSupported);
but when I try to get the error content in
var r = (HttpWebResponse)(request.GetResponse());
if (r.StatusCode != HttpStatusCode.OK) {...
The problem is that GetResponse() throws a WebException error. And it is impossible for me to get the "bla bla bla" text. How can I get this text? The web exception contains the status code HttpVersionNotSupported but no property that contains the text "bla bla bla". Where is the data I send as first parameter of WebFaultException?
Try using the HttpWebResponse.GetResponseStream method to access the contents of the response. The sample code in the link should you show how to read and clean up the stream.
这篇关于httpWebRequest - 获取错误内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!