Sqlserver調用api

來源:互聯網
上載者:User

標籤:als   urlencode   config   webapi   使用   sub   roc   app   declare   

雖然使用sqlserver去調用服務介面的情況比較少,但也可以去瞭解下對應的使用方式

一、首先要開啟組件的配置

sp_configure ‘show advanced options‘, 1;GORECONFIGURE;GOsp_configure ‘Ole Automation Procedures‘, 1;GORECONFIGURE;GOEXEC sp_configure ‘Ole Automation Procedures‘;GO

二、調用webservice

1、調用webservice的時候建議使用fiddler去擷取一下發送資料過程用contenttype的類型以及調用介面的資料

2、使用sqlserver調用對應的介面以及結果

declare @ServiceUrl as varchar(1000) set @ServiceUrl = ‘http://localhost:19930/LoginWebService.asmx/Login‘DECLARE @data varchar(max);set @data=‘username=8&password=7‘                  Declare @Object as IntDeclare @ResponseText AS  varchar(1000)   ;      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/x-www-form-urlencoded‘Exec sp_OAMethod @Object, ‘send‘, NULL, @data --發送資料Exec sp_OAMethod @Object, ‘responseText‘, @ResponseText OUTPUTEXEC sp_OAGetErrorInfo @Object --異常輸出Select  @ResponseText Exec sp_OADestroy @ObjectGO

二、調用webapi、兩者調用的方式基本如出一轍

1、同樣使用fiddler擷取介面調用資訊(因為該介面是GET就不需要看所傳的參數)

2、介面調用以及結果

GET操作

declare @ServiceUrl as varchar(1000) set @ServiceUrl = ‘http://xxxxx.com/beijing/139/1000000/TaxInfo?token=6d83d2adcff64594bd68614b6ae9e1c8‘DECLARE @data varchar(max);set @data=‘‘                  Declare @Object as IntDeclare @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 OUTPUTEXEC sp_OAGetErrorInfo @Object --異常輸出Select  @ResponseText Exec sp_OADestroy @ObjectGO

 

POST操作

declare @ServiceUrl as varchar(1000) set @ServiceUrl = ‘http://xxxx.com/Feedback/Estimate‘DECLARE @data varchar(max);--發送資料set @data=‘CityName=SubmitSystemName=%E7%99%BE%E5%BA%A6%E5%8F%8D%E9%A6%88&OriginID=2d90660c-436c-4e12-bfa6-e849a06b2c51&Price=10000&IsAccurate=False&PriceType=1&UserKeyId=a669e4ec7bdc47a7b6c2c334ebe1a50c&signature=X8p3lIZT0Ba3LeiC6irm3%2FMnlE8%3D&time=1452735047291‘                   Declare @Object as IntDeclare @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/x-www-form-urlencoded‘Exec sp_OAMethod @Object, ‘send‘, NULL, @data --發送資料Exec sp_OAMethod @Object, ‘responseText‘, @ResponseText OUTPUTEXEC sp_OAGetErrorInfo @Object --異常輸出Select  @ResponseText Exec sp_OADestroy @ObjectGO

  

 

Sqlserver調用api

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.