SQL Server儲存過程模擬HTTP請求POST和GET協議

icyhoo發表於2020-05-23
/****** 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

 

相關文章