Calling an API from SQL Server stored procedure

后端 未结 7 525
暖寄归人
暖寄归人 2020-11-28 04:23

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/getRespons         


        
7条回答
  •  无人及你
    2020-11-28 04:41

    I'd recommend using a CLR user defined function, if you already know how to program in C#, then the code would be;

    using System.Data.SqlTypes;
    using System.Net;
    
    public partial class UserDefinedFunctions
    {
     [Microsoft.SqlServer.Server.SqlFunction]
     public static SqlString http(SqlString url)
     {
      var wc = new WebClient();
      var html = wc.DownloadString(url.Value);
      return new SqlString (html);
     }
    }
    

    And here's installation instructions; https://blog.dotnetframework.org/2019/09/17/make-a-http-request-from-sqlserver-using-a-clr-udf/

提交回复
热议问题