Created
May 28, 2012 15:33
-
-
Save mdnmdn/2819763 to your computer and use it in GitHub Desktop.
SQL Server http get function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sp_configure 'Ole Automation Procedures', 1; | |
GO | |
RECONFIGURE; | |
GO | |
CREATE function fn_get_http | |
( | |
@url varchar(8000) | |
) | |
returns varchar(8000) | |
as | |
BEGIN | |
DECLARE @win int | |
DECLARE @hr int | |
DECLARE @text varchar(8000) | |
EXEC @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1',@win OUT | |
IF @hr <> 0 EXEC sp_OAGetErrorInfo @win | |
EXEC @hr=sp_OAMethod @win, 'Open',NULL,'GET',@url,'false' | |
IF @hr <> 0 EXEC sp_OAGetErrorInfo @win | |
EXEC @hr=sp_OAMethod @win,'Send' | |
IF @hr <> 0 EXEC sp_OAGetErrorInfo @win | |
EXEC @hr=sp_OAGetProperty @win,'ResponseText',@text OUTPUT | |
IF @hr <> 0 EXEC sp_OAGetErrorInfo @win | |
EXEC @hr=sp_OADestroy @win | |
IF @hr <> 0 EXEC sp_OAGetErrorInfo @win | |
RETURN @text | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment