从 SQL Server 存储过程调用 API [英] Calling an API from SQL Server stored procedure

查看:170
本文介绍了从 SQL Server 存储过程调用 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 ASP.NET Web 窗体调用 API 非常简单.

Calling an API from ASP.NET Web Form is very easy.

WebClient wc = new WebClient();
string urlData = wc.DownloadString("http://xxx.xxx.xx.xx/sssss/getResponse.do?ID=testing");

但是我们可以从 SQL Server 存储过程调用 API.

But can we call an API from SQL Server stored procedure.

如果是,那么我们如何从 SQL Server 存储过程调用 API 以及如何获得 API 响应?

If yes then how can we call an API from a SQL Server stored procedure and how can we get API response?

推荐答案

请看链接 了解更多详情.

Declare @Object as Int;
Declare @ResponseText as Varchar(8000);

Code Snippet
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
                 'http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT', --Your Web Service Url (invoked)
                 'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText

Exec sp_OADestroy @Object

这篇关于从 SQL Server 存储过程调用 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆