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