How can I make HTTP request from SQL server?
I got answer by powershell. What I did is open powershell in sql server then I did execute following code in powershell.
$http_Request= New-Object system.Net.WebClient;
$Result = $http_Request.downloadString("url")
I got another answer as well. I created procedure like follows
CREATE procedure HTTP_Request( @sUrl varchar(200))
As
Declare
@obj int
,@hr int
,@msg varchar(255)
exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
if @hr <> 0 begin Raiserror('sp_OACreate MSXML2.ServerXMLHttp.3.0
failed', 16,1) return end
exec @hr = sp_OAMethod @obj, 'open', NULL, 'POST', @sUrl, false
if @hr <>0 begin set @msg = 'sp_OAMethod Open failed' goto eh end
exec @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type',
'application/x-www-form-urlencoded'
if @hr <>0 begin set @msg = 'sp_OAMethod setRequestHeader failed' goto
eh end
exec @hr = sp_OAMethod @obj, send, NULL, ''
if @hr <>0 begin set @msg = 'sp_OAMethod Send failed' goto eh end
exec @hr = sp_OADestroy @obj
return
eh:
exec @hr = sp_OADestroy @obj
Raiserror(@msg, 16, 1)
return
GO
I called the stored procedure with url
USE [master]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[HTTP_Request]
@sUrl = N'url'
SELECT 'Return Value' = @return_value
GO
Thank you guys to make me work this.