我正在尝试使用对 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 并处理异常?
提前致谢。