网上下的一段代码,访问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

解决方案 »

  1.   

    不怎么懂.net,但我用vb的话,要解决cookie问题多办用XMLHTTP来实现的。
      

  2.   

    收藏!谢谢!
    ------------------
    IOAS:易学易用、灵活自由、个人免费使用的办公系统速成工具。
    详情请访问:www.ioas.net
    ------------------
      

  3.   

    LZ,把代码贴齐了,Dts.Events.FireInformation()  这个事件委托函数在哪儿呢?
      

  4.   

    回楼上的朋友,应该在Microsoft.SqlServer.Dts.Runtime里面,是SQL Server DTS的东西,这个不重要.
    关键是
    MyWebClient.Credentials = New System.Net.NetworkCredential("UserName", "Password")
    MyWebClient.DownloadFile(RemoteUri, LocalFileName)我下载下来的文件不是我要的数据文件,而是让我输入用户名和密码的那个页面.如何才能通过验证下载到我要的文件呢?