SQL Server调用WebAPI和WebService

SQLSERVER调用WebAPI和WebService
SqlServer调用webapi和webService接口

declare @url nvarchar(max) 
set @url = 'http://XXX/GetToken' --API地址
declare @pms nvarchar(max)
--set @pms='{"Username":"Test","Password":"Test"}'   --参数
set @pms = (select 'Test' as 'Username', 'Test' as 'Password' for json path, WITHOUT_ARRAY_WRAPPER)
declare @object int
declare @responseText nvarchar(4000);      
exec sp_OACreate 'WinHttp.WinHttpRequest.5.1', @object out
exec sp_OAMethod @object, 'open', null, 'POST',@url,'false'
exec sp_OAMethod @object, 'setRequestHeader', null, 'Content-Type','application/json;charset=UTF-8'
exec sp_OAMethod @object, 'send', null, @pms --发送数据
exec sp_OAMethod @object, 'responseText', @responseText output
--exec sp_OAGetErrorInfo @object --异常输出
select @responseText as ResponseText
exec sp_OADestroy @object
GO
posted @ 2023-02-07 17:06  vvull  阅读(284)  评论(0编辑  收藏  举报