我目前正在尝试自动化从源系统(Apptio)到目标系统(PCM)的提要。我实际上是在尝试使用内置 API 将 .tsv 文件下载到共享驱动器位置,然后触发导入作业以将该文件处理为 PCM。
然而,我在调用 API 并获取文件下载方面有点卡住,并尝试了一些方法,我认为其中一种方法可行,但不是很可靠。
我尝试使用 wscript.exe 从 CMD 提示符调用以下 VBScript ...
Dim oXMLHTTP
Dim oStream
dim urlstr
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
urlstr = "https://SITE.apptio.com/biit/api/v1.tsv?date=Apr%3AFY2013&dataPath=-%40CSITE.co.uk%253AService%2BCosting%2Bv2%2FReports%2F.DateGoesHere%2FCostModels%2FDefault%2F.View%253Atab%253AService%2BCosting%2F.View%253AApptio%2BSandbox%2F.View%253"
urlstr = urlstr & "AABM%2FABM%2BOutput%2F%21GROUPBY%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%255D%2F.Summary%2F%21NEWCOLUMN%255B%257BLTM%2BFixed%257D%253DPreviousYear%28Fixed%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BSemi%2BVariable%257D%253DPreviousYear%28Semi%2BVariable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BVariable%257D%253DPreviousYear%28Variable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BCost%257D%253DPreviousYear%28Cost%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21SORT%255B%257BLTM%2BCost%257D%257Cdesc%255D%2F%21LIMIT%255B0%252C2147483647%252Cadd_total%255D%2F%21LIMIT_COLUMNS%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%252C%257BLTM%2BFixed%257D%252C%257BLTM%2BSemi%2BVariable%257D%252C%257BLTM%2BVariable%257D%252C%257BLTM%2BCost%257D%255D%255B%255D%255B%255D%255B'orderByIncludeList%255D"
oXMLHTTP.Open "GET", urlstr, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile "\\csdatg08\FinanceTransformationFM\Transformation\Josh\ABM Transfer\Apptio\DataFeed\Output.tsv"
oStream.Close
End If
然而,这给了我一个错误:
(12, 1) msxml3.dll:访问被拒绝。
我认为这与我调用 API 的事实有关。我尝试使用托管在同一服务器上的图形的 URL,这将下载指定的位置而不会出现问题。
我还尝试将 URl 直接粘贴到浏览器中。URL 提示进行用户身份验证(我希望如此),但随后会弹出另存为对话框,显示 URL 是正确的。
所以.. 然后我尝试了一个脚本来启动一个 IE 实例,允许登录提示,等待另存为对话框,然后发送密钥来保存文件。
虽然这确实有效 - 我不相信它。I>E 如果进程在不同版本的 IE 上运行会发生什么,会发生什么另存为对话框打开...。
所以我想看看是否有人知道在我们走完整的 SQL 链接路线之前是否有更好的方法,这将是非常昂贵的,而且对于我们正在做的事情可能过度。
谢谢
(第二个代码如下)
Dim objExplorer : Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "https://SITE.apptio.com/biit/api/v1.tsv?date=Apr%3AFY2013&dataPath=-%40CSITE.co.uk%253AService%2BCosting%2Bv2%2FReports%2F.DateGoesHere%2FCostModels%2FDefault%2F.View%253Atab%253AService%2BCosting%2F.View%253AApptio%2BSandbox%2F.View%253AABM%2FABM%2BOutput%2F%21GROUPBY%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%255D%2F.Summary%2F%21NEWCOLUMN%255B%257BLTM%2BFixed%257D%253DPreviousYear%28Fixed%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BSemi%2BVariable%257D%253DPreviousYear%28Semi%2BVariable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BVariable%257D%253DPreviousYear%28Variable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BCost%257D%253DPreviousYear%28Cost%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21SORT%255B%257BLTM%2BCost%257D%257Cdesc%255D%2F%21LIMIT%255B0%252C2147483647%252Cadd_total%255D%2F%21LIMIT_COLUMNS%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%252C%257BLTM%2BFixed%257D%252C%257BLTM%2BSemi%2BVariable%257D%252C%257BLTM%2BVariable%257D%252C%257BLTM%2BCost%257D%255D%255B%255D%255B%255D%255BorderByIncludeList%255D"
objExplorer.ToolBar = 1
objExplorer.StatusBar = 1
objExplorer.Width = 800
objExplorer.Height = 800
objExplorer.Left = 1
objExplorer.Top = 1
objExplorer.Visible = 1
wscript.echo "window open"
wscript.sleep 6000
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("File Download")
If ret = True Then
wshShell.SendKeys "%S"
Exit Do
End If
WScript.Sleep 500
Loop
wscript.echo "Save Selected"
Do
ret = wshShell.AppActivate("Save As")
If ret = True Then
wshShell.SendKeys "%S"
Exit Do
End If
WScript.Sleep 500
Loop
wscript.echo "File Saved"
到目前为止的参考资料:
如何使用 VB 脚本处理 IE 下载对话框? VBScript 检测打开的消息框并关闭它 http://www.pctools.com/guides/scripting/detail/149/?act=reference