zoukankan      html  css  js  c++  java
  • sql server 利用存储过程http请求调用URL链接访问方法

    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

    开启权限配置

    DECLARE    @return_value int,
            @status int
    
    EXEC    @return_value = [dbo].[P_HttpRequestData]
            @URL = N'https://test.GoldApi.com/Api/GetGoldSales',
            @status = @status OUTPUT
    
    SELECT    @status as N'@status'

    调用存储

    USE [Test]
    GO
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[P_GetGoldSales] 
    AS
    set nocount on               
    set transaction isolation level read uncommitted               
    set xact_abort on 
    
    exec [P_HttpRequestData] 'https://test.GoldApi.com/Api/GetGoldSales'

    存储调用存储

    USE [Test]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[P_HttpRequestData]

    ( @URL varchar(500), @status int=0 OUT,
    @returnText nvarchar(2000)='' OUT )
    AS BEGIN DECLARE @object int,--声明变量 @errSrc int --声明变量 /*初始化*/ EXEC @status = SP_OACreate 'Msxml2.ServerXMLHTTP.3.0', @object OUT; IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END /*创建链接*/ EXEC @status= SP_OAMethod @object,'open',NULL,'GET',@URL IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END EXEC @status=SP_OAMethod @object,'setRequestHeader','Content-Type','application/x-www-form-urlencoded' /*发起请求信息*/ EXEC @status= SP_OAMethod @object,'send',NULL IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END
    /*获取返回*/  
      EXEC @status= SP_OAGetProperty @object,'responseText',@returnText OUT
       IF @status <> 0   
    BEGIN   
    EXEC SP_OAGetErrorInfo @object, @errSrc OUT  
      RETURN
       END
    END;

     创建http请求的存储过程

     

    访问URL地址的 API控制器中创建方法

     public void GetGoldSales(DataRequest<int> request, DataResponse<ResultModel> response)
            {
                var result = new ResultModel();
                result.Status = ResultStatus.Success;
                result.Message = "获取信息成功!";
                try
                {
    var Goldno =string.Empty();
    var List = GetList(request.ObjectData); if (List.Count > 0) {foreach (var item in List) { Goldno+= item + " "; } if (Goldno!=null) { var str = $"货物上架的销售价格异常 异常货品编号: {Goldno}请及紧急查看并修复!"; SendErrorMsg(str); } } } catch (Exception ex) { result.Status = ResultStatus.Fail; result.Message = "获取销售价格信息失败!" + ex.Message; } response.ObjectData = result; }
  • 相关阅读:
    JS优先队列排序。出队时,先找出优先级最高的元素,再按照先进先出出队。
    使用队列对数组排列,基数排序
    一个用JS数组实现的队列
    使用栈判断给定字符串是否是回文的算法
    使用js栈stack类的实现
    Bootstrap篇:弹出框和提示框效果以及代码展示
    一个漂亮的php验证码类
    jquery单选框radio绑定click事件实现和是否选中的方法
    phpQuery—基于jQuery的PHP实现
    PHP的函数-----生成随机数、日期时间函数
  • 原文地址:https://www.cnblogs.com/Warmsunshine/p/12016826.html
Copyright © 2011-2022 走看看