【发布时间】:2012-05-14 10:28:57
【问题描述】:
我在那里问了一个类似的问题,但针对 curl 和 webclient。
我找到了 curl 的答案:
How to ensure that webclient/curl process 503 error like they process 200
CURLOPT_FAILONERROR
我想要类似的东西,但对于 webclient 而不是 curl
【问题讨论】:
我在那里问了一个类似的问题,但针对 curl 和 webclient。
我找到了 curl 的答案:
How to ensure that webclient/curl process 503 error like they process 200
CURLOPT_FAILONERROR
我想要类似的东西,但对于 webclient 而不是 curl
【问题讨论】:
每个问题的提问方式可能意味着该问题与该问题中所链接的问题重复。无论如何,我在这里提供与那里相同的答案:
对于WebClient,您需要处理WebException.Response。例如。此 LINQPad 查询转储了我的 Web 服务器的“未找到”错误网页提供的 HTML:
Dim wc = New System.Net.WebClient
Try
Dim rd = wc.DownloadData(New Uri("http://localhost/test"))
rd.Dump
Catch Ex As System.Net.WebException
Dim rs = Ex.Response
Call (New StreamReader(rs.GetResponseStream)).ReadToEnd.Dump
End Try
【讨论】:
Dump 只是 LINQPad 的 Console.WriteLine 等价物,但格式更多。
DownloadData内抛出的,所以流需要在Catch内处理。