亲宝软件园·资讯

展开

SQL Server存储过程模拟HTTP请求POST和GET协议

icyhoo 人气:0
/****** Object:  StoredProcedure [dbo].[sp_http_get]    Script Date: 05/23/2020 15:47:09 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[sp_http_get](
    @URL varchar(500),
    @ResponseText varchar(8000) OUTPUT
)
AS
BEGIN

Declare @Status as Int   
Exec sp_OACreate 'Msxml2.ServerXMLHTTP.3.0', @Status OUT;
Exec sp_OAMethod @Status, 'open', NULL, 'GET',@URL,'false'
Exec sp_OAMethod @Status, 'send', NULL, NULL
Exec sp_OAMethod @Status, 'responseText', @ResponseText OUTPUT
if @Status<>0
  begin
    EXEC sp_OAGetErrorInfo @Status
  end
Exec sp_OADestroy @Status
END

GO


CREATE PROCEDURE [dbo].[sp_http_post](
    @URL varchar(500),
    @Data varchar(8000),
    @ResponseText varchar(8000) OUTPUT
)
AS
BEGIN

Declare @Status as Int   
Exec sp_OACreate 'Msxml2.ServerXMLHTTP.3.0', @Status OUT;
Exec sp_OAMethod @Status, 'open', NULL, 'POST',@URL,'false'
Exec sp_OAMethod @Status, 'send', NULL, @Data
Exec sp_OAMethod @Status, 'responseText', @ResponseText OUTPUT
if @Status<>0
  begin
    EXEC sp_OAGetErrorInfo @Status
  end
Exec sp_OADestroy @Status
END


GO

 

加载全部内容

相关教程
猜你喜欢
用户评论