2
我問了一個類似的問題,但對於curl和webclient。如何確保webclient處理錯誤,就像他們處理200
我發現捲曲的答案:
How to ensure that webclient/curl process 503 error like they process 200
CURLOPT_FAILONERROR
我想類似的東西,但對於Web客戶端,而不是捲曲
我問了一個類似的問題,但對於curl和webclient。如何確保webclient處理錯誤,就像他們處理200
我發現捲曲的答案:
How to ensure that webclient/curl process 503 error like they process 200
CURLOPT_FAILONERROR
我想類似的東西,但對於Web客戶端,而不是捲曲
的方式每一個問題是問,大概意思這個問題是與這個問題中鏈接的問題的重複。無論如何,我在這裏提供的答案與我在此處的相同:
對於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
當事情出錯時,會執行rd.Dump嗎?還是會異常直接? –
Wherre我可以看到這個dump thingy的文檔嗎?我沒有看到它轉儲 –
爲此,'轉儲'只是LINQPad的等同於'Console.WriteLine',但更多的格式。 –