使用HttpWebRequest从404错误中检索内容 [英] Retrieve content from 404 error using HttpWebRequest

查看:60
本文介绍了使用HttpWebRequest从404错误中检索内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用C#与LinkedIn API集成。当我制作一个  无效 调用API时,它可以返回像这样的HTTP响应(来自
Fiddler):

I am integrating with the LinkedIn API using C#. When I make an invalid call to the API, it can return a HTTP response like such (from Fiddler):

HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
x
-li-request-id: VL2EER2ROJ
Date: Tue, 16 Oct 2012 08:52:59 GMT
Vary: *
x
-li-format: xml
Content-Type: text/xml;charset=UTF-8
Content-Length: 266

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
 
<status>404</status>
 
<timestamp>1350377580000</timestamp>
 
<request-id>VL2EER2ROJ</request-id>
 
<error-code>0</error-code>
 
<message>Could not find member {/people/XXXXXX}</message>
</error>



我特意想得到错误xml,但是HttpWebRequest似乎只是抛出异常然后无关在我的调试器中,我可以看到内容长度是266,但任何尝试调用  (System.Net.WebException) .Response.GetResponseStream()结果
in  stream
不是可读
 例外。

I would specifically like to get at the error xml, however HttpWebRequest seems to simply throw the exception and then has nothing to do with the content. In my debugger, I can see that the content length is 266, but any attempt to call (System.Net.WebException).Response.GetResponseStream()results in a stream was not readable exception.


这种在非200 HTTP状态响应中返回错误消息的方法在Web API中似乎很流行 - 我希望在那里是一种获得这些回复的方法......

This method of returning error messages within a non 200 HTTP status response seems quite popular in web APIs - I'm hoping there is a way to get at these responses...

推荐答案

不,默认情况下,我的代码是写的,因此无法通过未经授权的用户。
No, by default, my code is written so that it cannot be reproduced by an unauthorized user.


这篇关于使用HttpWebRequest从404错误中检索内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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