Re: [SQL ] SQL Server 2008 R2 執行外部網址
※ 引述《pobie (嗯)》之銘言:
: 各位大大好,想請問一下
: xp_cmdshell 可以執行外部程式做很多事
: 但是我想問有沒有類似的東西可以執行外部網址呢?
: 因為小弟做了一個 trigger
: 想在 trigger 後去觸發 php
: 所以想要給一串網址例如 http://xxx.url/php.php?param=xxxxx
: 有查到可以用 xp_cmdshell 'C:\path\to\php\php.exe -f
: C:\Path\to\your\script.php'
: 執行 php.exe 來實作,但是做 trigger 的那台 DB Server 並沒有安裝 php
: 這方法該怎麼去實做呢?又或者 google 要怎麼下關鍵字比較好?
: 先感謝各位大大的解答了 :)
有兩個方案提供給您參考 --
甲案,在 Trigger 以 xp_cmdShell 跑 WSH,然後透過 WSH 叫用 PHP。詳細作法如下:
1. 在(例如) c:\temp 建立一個 ShellRun.vbs 程式檔案。(存檔時,編碼請用 Ansi)
程式內容:
Set Shell = WScript.CreateObject("WScript.Shell")
Shell.Run WScript.Arguments(0)
2. 在你的 Trigger 叫用 ShellRun.vbs,例如這樣:
xp_cmdshell 'dir c:\ > c:\temp\report.txt'
xp_cmdshell 'c:\temp\ShellRun.vbs "http://www.udn.com"'
乙案,不使用 xm_cmdShell,透過 OLE Automation 向 Web Server 發出 request。i.e.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Declare @Object as Int
Declare @ResponseText as Varchar(8000)
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://www.udn.com', 'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
Select @ResponseText
Exec sp_OADestroy @Object
GO
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.41.99.189
討論串 (同標題文章)