SSIS 中的 vb.net 脚本通过代理连接到网站
我正在尝试编写一个连接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用当前登录的凭据:
' WebRequest.DefaultWebProxy 是 xml.Load() 使用的代理设置
You can use the credentials of the currrent login with:
' WebRequest.DefaultWebProxy is the proxy settings used by xml.Load()
在 SSIS 2012 中完美运行 - 感谢
除了声明中的 Imports System.Net 之外,我的最终代码如下所示:
显然这是一个客户端代理 hack。
还没有在服务器上尝试过这个。
Worked perfectly in SSIS 2012 - thanks
Aside from the Imports System.Net in the declaration, my final code looked like this :
Obviously this is a client side proxy hack.
Haven't tried this on the server yet.