Skip to content

Instantly share code, notes, and snippets.

@mdnmdn
Created May 28, 2012 15:33
Show Gist options
  • Save mdnmdn/2819763 to your computer and use it in GitHub Desktop.
Save mdnmdn/2819763 to your computer and use it in GitHub Desktop.
SQL Server http get function
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