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 Post方法 --Post方法 declare @ServiceUrl as varchar(1000) set @ServiceUrl = 'http://www./api/GetToken' DECLARE @data varchar(max); --發(fā)送數(shù)據(jù) set @data='{"userName": "xxxxx","userSecret": "xxxxx"}' Declare @Object as Int Declare @ResponseText AS varchar(8000) ; Exec sp_OACreate 'Msxml2.ServerXMLHTTP.3.0', @Object OUT; Exec sp_OAMethod @Object, 'open', NULL, 'POST',@ServiceUrl,'false' Exec sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Type','application/json;charset=UTF-8' Exec sp_OAMethod @Object, 'send', NULL, @data --發(fā)送數(shù)據(jù) Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT --EXEC sp_OAGetErrorInfo @Object --異常輸出 Select @ResponseText Exec sp_OADestroy @Object Get方法 --Get方法 declare @ServiceUrl as varchar(1000) set @ServiceUrl = 'http://www./api/GetById?purchaseCode=PO23' DECLARE @data varchar(max); --發(fā)送數(shù)據(jù) set @data=null declare @token as nvarchar(3000) set @token='Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMjgiLCJVSWQiOiIyMjgiLCJVc2VySWQiOiJPSF9TMTAwMzIiLCJVc2VyTmFtZSI6IumFjeS7tuenkSIsIkJyYW5jaElkIjoiV1owMjE4IiwiQnJhbmNoTmFtZSI6IumFjeS7tuenkSIsIkNvbXBhbnlJZCI6Ik9IIiwiVmVuQ29kZSI6IldaMDIxOCIsIlZlbk5hbWUiOiLphY3ku7bnp5EiLCJleHAiOjE2OTE3NjA2NDAsImlzcyI6IndlYmFwaS5jbiIsImF1ZCI6IldlYkFwaSJ9.6JCkB8nPYLEZvh3UjXph9COawHhXgoMhhZB4UK8S-jo' 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, 'setRequestHeader', NULL, 'Content-Type','application/json;charset=UTF-8' Exec sp_OAMethod @Object, 'setRequestHeader', NULL, 'Authorization',@token Exec sp_OAMethod @Object, 'send', NULL, @data --發(fā)送數(shù)據(jù) Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT --EXEC sp_OAGetErrorInfo @Object --異常輸出 Select @ResponseText Exec sp_OADestroy @Object |
|