时间:2021-07-01 10:21:17 帮助过:29人阅读
//出发器
ALTER trigger [dbo].[trsx]
on [dbo].[T1]
for insert
as
BEGIN
DECLARE @URL VARCHAR(1000)
set @URL=‘http://192.168.1.xx/api/blade-meal/meal/menu/getMealPerson‘
exec DZ_HTTP_POST @URL;
END
GO
//存储过程
create procedure [dbo].[DZ_HTTP_POST] (
@URL varchar(1000)
)
as
begin
DECLARE @status int=0
DECLARE @object int
DECLARE @errSrc int
DECLARE @ResponseText nvarchar(2000)
/*初始化对*/
EXEC @status = SP_OACreate ‘Msxml2.ServerXMLHTTP.3.0‘, @object OUT
--print ‘--------object-------‘
--print @object
IF @status <> 0
BEGIN
EXEC SP_OAGetErrorInfo @object, @errSrc OUT
--print ‘--------errSrc-------‘
--print @errSrc
--RETURN
END
/*创建链接*/
EXEC @status= SP_OAMethod @object,‘open‘,NULL,‘POST‘,@URL OUT
--print ‘--------URL-------‘
--print @URL
IF @status <> 0
BEGIN
EXEC SP_OAGetErrorInfo @object, @errSrc OUT
--RETURN
END
EXEC @status=SP_OAMethod @object,‘setRequestHeader‘,‘Content-Type‘,‘application/x-www-form-urlencoded‘
/*发起请求*/
EXEC @status= SP_OAMethod @object,‘send‘,null
IF @status <> 0
BEGIN
EXEC SP_OAGetErrorInfo @object, @errSrc OUT
--RETURN
END
Exec sp_OAMethod @Object, ‘responseText‘, @ResponseText OUTPUT --@ResponseText为http返回的内容
--Select @ResponseText
--print @ResponseText
Exec sp_OADestroy @Object
end
sql server出发器 监听数据库
标签:creat ext 数据 post cat ons declare create src