SSIS 中的 vb.net 脚本通过代理连接到网站

发布于 2024-11-18 20:43:09 字数 882 浏览 0 评论 0原文

我正在尝试编写一个连接到 XML 源的 SSIS 包来下载外汇汇率并将其导入到 SQL 表中。

我有下面的代码,但无法弄清楚如何通过代理实现登录。

如果有人能想到一种更简单的方法来完成上述操作,我非常愿意尝试。

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.Net



Public Class ScriptMain

Public Sub Main()


    Dim xmlDoc As XmlDataDocument, strXML As String
    Dim client As System.Net.WebClient = New System.Net.WebClient()

    Dim cr As New System.Net.NetworkCredential("user", "password")
    Dim pr As New System.Net.WebProxy("proxy", 8080)

    pr.Credentials = cr
    client.Proxy = pr

    xmlDoc = New XmlDataDocument
    xmlDoc.Load("http://themoneyconverter.com/GBP/rss.xml")
    strXML = CType(xmlDoc.InnerXml, String)
    Dts.Variables("strXMLData").Value = strXML
    Dts.TaskResult = Dts.Results.Success
End Sub

End Class

非常感谢。

I am trying to write an SSIS package that connect to an XML feed to download FX rates and import them into an SQL table.

i have the code below, but cannot figure out how to implement logging in through a proxy.

if anyone can think of an easier way to do the above, i'm more than willing to give it a try.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.Net



Public Class ScriptMain

Public Sub Main()


    Dim xmlDoc As XmlDataDocument, strXML As String
    Dim client As System.Net.WebClient = New System.Net.WebClient()

    Dim cr As New System.Net.NetworkCredential("user", "password")
    Dim pr As New System.Net.WebProxy("proxy", 8080)

    pr.Credentials = cr
    client.Proxy = pr

    xmlDoc = New XmlDataDocument
    xmlDoc.Load("http://themoneyconverter.com/GBP/rss.xml")
    strXML = CType(xmlDoc.InnerXml, String)
    Dts.Variables("strXMLData").Value = strXML
    Dts.TaskResult = Dts.Results.Success
End Sub

End Class

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2024-11-25 20:43:09

您可以使用当前登录的凭据:

Imports System.Net

Dim Pr As New System.Net.WebProxy(Proxy, Port)
Pr.Credentials = System.Net.CredentialCache.DefaultCredentials
WebRequest.DefaultWebProxy = Pr

' WebRequest.DefaultWebProxy 是 xml.Load() 使用的代理设置

You can use the credentials of the currrent login with:

Imports System.Net

Dim Pr As New System.Net.WebProxy(Proxy, Port)
Pr.Credentials = System.Net.CredentialCache.DefaultCredentials
WebRequest.DefaultWebProxy = Pr

' WebRequest.DefaultWebProxy is the proxy settings used by xml.Load()

压抑⊿情绪 2024-11-25 20:43:09

在 SSIS 2012 中完美运行 - 感谢

除了声明中的 Imports System.Net 之外,我的最终代码如下所示:

 Dim Proxy As String, Port As Integer

 Proxy = "EnterYourProxyServerName"  
 Port = TypeInYourProxyPortAsANumber

 Dim Pr As New System.Net.WebProxy(Proxy, Port)  
 Pr.Credentials = System.Net.CredentialCache.DefaultCredentials
 WebRequest.DefaultWebProxy = Pr  
 Dts.TaskResult = ScriptResults.Success

显然这是一个客户端代理 hack。

还没有在服务器上尝试过这个。

Worked perfectly in SSIS 2012 - thanks

Aside from the Imports System.Net in the declaration, my final code looked like this :

 Dim Proxy As String, Port As Integer

 Proxy = "EnterYourProxyServerName"  
 Port = TypeInYourProxyPortAsANumber

 Dim Pr As New System.Net.WebProxy(Proxy, Port)  
 Pr.Credentials = System.Net.CredentialCache.DefaultCredentials
 WebRequest.DefaultWebProxy = Pr  
 Dts.TaskResult = ScriptResults.Success

Obviously this is a client side proxy hack.

Haven't tried this on the server yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文