sqlserver調用webapi

1.開啓組件(2012以上版本支持)api

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.調用apispa

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

 

返回結果:code

 

相關文章
相關標籤/搜索