• sqlserver使用存储过程发送http请求


    1.要使用这个功能需要先开启Sql Server 通讯配置--

    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

    2.建一个存储过程[P_GET_HttpRequestData]

    GO
    /****** Object: StoredProcedure [dbo].[P_GET_HttpRequestData] Script Date: 11/21/2019 08:38:32 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    Create PROCEDURE [dbo].[P_GET_HttpRequestData](
    @URL varchar(500),
    @status int=0 OUT
    )
    AS
    BEGIN
    DECLARE @object int,
    @errSrc int
    /*初始化对*/
    declare @str nvarchar(200)
    declare @ResponseText nvarchar(200)
    EXEC @status = SP_OACreate 'Msxml2.ServerXMLHTTP.3.0', @object OUT;
    print '===================='
    print @object
    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
    print '--------------------------------'
    print @str

    print '--------------------------------'
    print @status
    IF @status <> 0
    BEGIN
    EXEC SP_OAGetErrorInfo @object, @errSrc OUT
    RETURN
    END
    Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT --@ResponseText为http返回的内容

    Select @ResponseText
    print @ResponseText
    Exec sp_OADestroy @Object
    END;

    3.调用存储过程执行Url

    declare @url varchar(1000)

    declare  @ddip varchar(100)

    declare  @vipno varchar(100)

    --取IP地址

    SELECT @ddip=sysvalue FROM s_sys where syscode='ddip' 

    --取需要同步的会员编号

     select @vipno=c_vipno from inserted

    --拼接url地址
     set @url='http://'+@ddip+'/DDAPI.aspx?type=tongbuVip&&bh='+@vipno

    执行url
    EXECUTE P_GET_HttpRequestData @url

  • 相关阅读:
    (数据挖掘-入门-6)十折交叉验证和K近邻
    (数据挖掘-入门-5)基于内容的协同过滤与分类
    (数据挖掘-入门-4)基于物品的协同过滤
    (数据挖掘-入门-3)基于用户的协同过滤之k近邻
    (数据挖掘-入门-2)相似度衡量的方法
    (数据挖掘-入门-1)基于用户的协同过滤之最近邻
    SDL播放声音
    清空目录
    yuv转bmp
    ffmpeg解码视频流
  • 原文地址:https://www.cnblogs.com/linjincheng/p/11903468.html
Copyright © 2020-2023  润新知