作者TeemingVoid (TeemingVoid)
看板Database
标题Re: [SQL ] SQL Server 2008 R2 执行外部网址
时间Sat Nov 10 02:07:34 2012
※ 引述《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