如何从url下载文件 [英] how to downlaod file from url
本文介绍了如何从url下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的先生,
i我使用下面的代码从url下载一些文件
但我得到的错误就像
远程服务器返回错误:(403)禁止。
Respected sir,
i am using following code for download some file from url
but i get error like
" The remote server returned an error: (403) Forbidden."
Dim sSourceUrl As String
Dim DownFilePath As String
sSourceUrl = "http://www.nseindia.com/archives/equities/mto/MTO_17012013.DAT"
DownFilePath = "C:\abc.txt"
DownloadFile(sSourceUrl, DownFilePath)
Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)
Try
Dim _WebClient As New System.Net.WebClient()
WebClient.DownloadFile(_URL, _SaveAs)
Catch _Exception As Exception
MsgBox(_Exception.Message)
End Try
End Sub
有吗另一种方法,
请帮助我,
谢谢
Is there another way to do this,
Please help me,
Thank you
推荐答案
Protected Sub btnCopy_Click(sender As Object, e As EventArgs)
Try
Dim filename As String = "abcd.mp3"
Dim sourcePath As String = "\\is-pc634\Shared\"
'--------Download Option-----------
Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
response.ClearContent()
response.Clear()
response.ContentType = "audio/x-wav"
response.AddHeader("Content-Disposition", "attachment; filename=" & fileName & ";")
response.TransmitFile(sourcePath)
response.Flush()
response.End()
Else
msgBox("File cannot be downloaded.")
End If
Catch ex As Exception
msgBox(ex.Message)
End Try
End Sub
希望它可以帮助你..
hope it helps u..
这篇关于如何从url下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文