1.开启组件(2012以上版本支持)
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures', 1; GO RECONFIGURE; GO EXEC sp_configure 'Ole Automation Procedures'; GO
2.调用api
declare @ServiceUrl as varchar(1000) set @ServiceUrl = 'http://localhost:52261/Api/Values' DECLARE @data varchar(max); set @data='' Declare @Object as Int Declare @ResponseText AS varchar(8000) ; Exec sp_OACreate 'Msxml2.ServerXMLHTTP.3.0', @Object OUT; Exec sp_OAMethod @Object, 'open', NULL, 'GET',@ServiceUrl,'false' Exec sp_OAMethod @Object, 'send', NULL, @data --发送数据 Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT EXEC sp_OAGetErrorInfo @Object --异常输出 Select @ResponseText Exec sp_OADestroy @Object GO
返回结果: