SQL Server Invoke API

Source: Internet
Author: User
Tags ole

Although the use of SQL Server to invoke the service interface is relatively small, but also to understand the corresponding use of the situation

First, to open the configuration of the component

sp_configure ' show advanced options ', 1; Goreconfigure; Gosp_configure ' Ole Automation procedures ', 1; Goreconfigure; goexec sp_configure ' Ole Automation procedures '; GO

Second, call WebService

1. When calling WebService, it is recommended to use Fiddler to get the type of contenttype and the data of the calling interface when sending the data.

2. Use SQL Server to invoke the corresponding interface and result

Declare @ServiceUrl as varchar 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 (+)   ;      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--Send data Exec sp_OAMethod @Object, ' ResponseText ', @ResponseText outputexec sp_oageterrorinfo @Object--Abnormal output Select  @ResponseText Exec sp_ Oadestroy @ObjectGO

Second, call Webapi, the two call the way basically the same

1. Also use Fiddler to get the interface call information (because the interface is get it does not need to see the arguments passed)

2. Interface calls and results

Get operation

Declare @ServiceUrl as varchar 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--Send data Exec sp_OAMethod @Object, ' responsetext ', @ResponseText outputexec sp_oageterrorinfo @Object--Abnormal output Select  @ ResponseText Exec sp_OADestroy @ObjectGO

 

Post operation

Declare @ServiceUrl as varchar set @ServiceUrl = ' http://xxxx.com/Feedback/Estimate ' declare @data varchar (max);-- Send data 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--Send data Exec sp_OAMethod @Object, ' ResponseText ', @ResponseText outputexec sp_oageterrorinfo @Object--Abnormal output Select  @ResponseText Exec sp_ Oadestroy @ObjectGO

  

SQL Server Invoke API

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.