1

DownloadFile への Net.WebClient 呼び出しを使用してファイルをダウンロードしようとしています

Using client As New Net.WebClient()   
  Try
    client.DownloadFile(PDFURL, FullPDFFilePath)

次に、例外をキャッチし、403、404、または 500 エラー (呼び出し先のシステムで最も一般的なタイプ) のメッセージをチェックします。

 Catch ex as exception
   If exceptionMessage.Contains("(403)") Then 'Forbidden
     LogInformation("403 returned on download for " + CRPOrderNum, "DownloadLabels")

   ElseIf exceptionMessage.Contains("(404)") Then 'Not Found
     LogInformation("404 returned on download for " + CRPOrderNum, "DownloadLabels")

   else
     'blah blah
   end if
 finally
 end try

DownloadFile を呼び出して例外を処理する代わりに、ファイルを要求できる丁寧な方法はありますか?

前もって感謝します。

4

1 に答える 1

2

「丁寧な」方法は、HEAD リクエストを送信することです。残念ながら、WebClient はこれをネイティブにサポートしていないため、独自に作成するか、代わりに HttpWebRequest を使用する必要があります。

于 2011-05-11T15:36:54.203 に答える