网上下的一段代码,访问URL时加了密码也没用,下载下来的文件不是我要的数据文件,而是让我输入密码的那个页面.' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.Imports System
Imports System.Net
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.RuntimePublic Class ScriptMain
Public Sub Main()
Dim MyWebClient As WebClient
Dim RemoteUri As String
Dim LocalFileName As String
Dim FireAgain As Boolean
Try
MyWebClient = New WebClient()
' get the context from variables
RemoteUri = "http://abc.com/DataUniverse.aspx?SecurityTypeId=ST00000001"
LocalFileName = "C:\Test.html"
' tell the user what we're downloading where
Dts.Events.FireInformation(0, String.Empty, String.Format("Downloading '{0}' from '{1}'", LocalFileName, RemoteUri), String.Empty, 0, FireAgain)
' do the actual download
MyWebClient.Credentials = New System.Net.NetworkCredential("UserName", "Password")
MyWebClient.DownloadFile(RemoteUri, LocalFileName)
Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
' post the error message we got back.
Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
End Class
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.Imports System
Imports System.Net
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.RuntimePublic Class ScriptMain
Public Sub Main()
Dim MyWebClient As WebClient
Dim RemoteUri As String
Dim LocalFileName As String
Dim FireAgain As Boolean
Try
MyWebClient = New WebClient()
' get the context from variables
RemoteUri = "http://abc.com/DataUniverse.aspx?SecurityTypeId=ST00000001"
LocalFileName = "C:\Test.html"
' tell the user what we're downloading where
Dts.Events.FireInformation(0, String.Empty, String.Format("Downloading '{0}' from '{1}'", LocalFileName, RemoteUri), String.Empty, 0, FireAgain)
' do the actual download
MyWebClient.Credentials = New System.Net.NetworkCredential("UserName", "Password")
MyWebClient.DownloadFile(RemoteUri, LocalFileName)
Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
' post the error message we got back.
Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
End Class
------------------
IOAS:易学易用、灵活自由、个人免费使用的办公系统速成工具。
详情请访问:www.ioas.net
------------------
关键是
MyWebClient.Credentials = New System.Net.NetworkCredential("UserName", "Password")
MyWebClient.DownloadFile(RemoteUri, LocalFileName)我下载下来的文件不是我要的数据文件,而是让我输入用户名和密码的那个页面.如何才能通过验证下载到我要的文件呢?