如何从 SSIS 发出 HTTP 请求?
我有兴趣了解如何从 SSIS 进行 HTTP 调用。例如,我希望能够从 http://www.domain.com/resource.zip
下载文件并记录下载的日期时间和文件在驱动器上的目的地。我还想捕获文件大小等属性并捕获日期和时间。下载完成的时间。
I'm interested in knowing how I can make an HTTP call from SSIS. For example, I would like to be able to download a file from http://www.domain.com/resource.zip
and record the datetime of the download and the destination of the file on the drive. I would also like to capture such attributes as file size and capture the date & time when the download completed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以利用命名空间
System.Net.WebClient
在 SSIS 中的Script Task
的帮助下发出 Http 请求。以下示例展示了如何实现这一点。该示例是在SSIS 2008 R2
中创建的。分步过程:
创建一个新的 SSIS 包并创建两个变量,即 RemoteUri 和 LocalFolder。将变量
RemoteUri
设置为值http://www.google.com/intl/en_com/images/srpr/logo1w.png
。这是 Google 主页上徽标的图像 URL。将变量LocalFolder
设置为值C:\temp\
。这是我们要保存内容的路径。请参阅屏幕截图#1。在 SSIS 包上,放置一个
脚本任务
。将脚本任务中的 Main() 方法替换为脚本任务代码部分下提供的代码。请参阅屏幕截图#2。屏幕截图 #3 显示路径
C:\temp\
为空。屏幕截图#4 显示包的成功执行。
屏幕截图 #5 显示内容(在本例中为徽标图像)已下载到本地文件夹路径。
屏幕截图 #6 显示该代码经过测试可以下载 .zip 文件。为了实现此目的,变量 RemoteUri 的值已更改为需要下载的内容 url。
脚本任务代码:
C#代码,只能在
SSIS 2008及更高版本
中使用。屏幕截图 #1:
屏幕截图 #2:
屏幕截图#3:
屏幕截图 #4:
屏幕截图 #5:
屏幕截图 #6:
You can make use of the namespace
System.Net.WebClient
to make the Http request with the help ofScript Task
in SSIS. Following example shows how this can be achieved. The example was created inSSIS 2008 R2
.Step-by-step process:
Create a new SSIS package and create two variables namely RemoteUri and LocalFolder. Set the variable
RemoteUri
with the valuehttp://www.google.com/intl/en_com/images/srpr/logo1w.png
. this is the image url of the logo on the Google's home page. Set the variableLocalFolder
with the valueC:\temp\
. this is the path where we are going to save the content. Refer screenshot #1.On the SSIS package, place a
Script Task
. Replace the Main() method within the script task with the code provided under the Script Task Code section. Refer screenshot #2.Screenshot #3 shows that the path
C:\temp\
is empty.Screenshot #4 shows successful execution of the package.
Screenshot #5 shows that the content (in this case the logo image) has been downloaded to the local folder path.
Screenshot #6 shows that the code was tested to download a .zip file. To achieve this, the value of the variable RemoteUri was changed with the content url that needs to be downloaded.
Script task code:
C# code that can be used only in
SSIS 2008 and above
.Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
只是 @user756519 脚本的替代方案,速度不那么快,但更防弹。
这样,webClient 就不会保持挂起状态,而且您也不依赖于先前存在的 C:\Temp 目录。
除此之外,@user756519 的回答很好,非常详细。
Just an alternative for @user756519 script, not as fast, but more bulletproof
This way, webClient doesn't stay hanging, and also you're not dependent on the previous existence of C:\Temp directory.
Other than that, great answer from @user756519, very detailed.
以下是几个选项:
脚本任务示例位于:
http://microsoft-ssis.blogspot .com/2011/05/download-source-file-from-website-with.html
Here are a couple of options:
Script Task Examples at:
http://microsoft-ssis.blogspot.com/2011/05/download-source-file-from-website-with.html