Hello!
I am trying to complete a HTTP post request via a stored proc.
The query returns the error: sp_OAMethod http status 407 which leads me to think proxy issues and that the request is never making it to the server. The prints are in there for troubleshooting and it seems to break after step 5.
Any help would be greatly appreciated
Thanks!
CODE---------------------
USE [db]
GO
/****** Object: StoredProcedure [dbo].[HTTP_POST] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[HTTP_POST]( @sUrl varchar(8000)='
https://api.apiurl/oauth/token?grant_type=refresh_token&client_id=
xxxxxxx&client_secret=XXXX
-XXXX&refr
esh_token=
XXXXXXX', @response varchar(8000)
out)
As
Declare
@obj int
,@hr int
,@status int
,@msg varchar(255)
print @msg
exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
if @hr <> 0 begin Raiserror('sp_OACreate MSXML2.ServerXMLHttp.3.0
failed', 16,1) return end
print '1'
exec @hr = sp_OAMethod @obj, 'open', NULL, 'POST', @sUrl, false
if @hr <>0 begin set @msg = 'sp_OAMethod Open failed' goto eh end
print '2'
exec @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type',
'application/x-www-form-ur
lencoded'
if @hr <>0 begin set @msg = 'sp_OAMethod setRequestHeader failed' goto
eh end
print '3'
exec @hr = sp_OAMethod @obj, send, NULL, ''
if @hr <>0 begin set @msg = 'sp_OAMethod Send failed' goto eh end
print '4'
exec @hr = sp_OAGetProperty @obj, 'status', @status OUT
if @hr <>0 begin set @msg = 'sp_OAMethod read status failed' goto
eh
end
print '5'
if @status <> 200 begin set @msg = 'sp_OAMethod http status ' +
str(@status) goto eh end
print '6'
exec @hr = sp_OAGetProperty @obj, 'responseText', @response OUT
if @hr <>0 begin set @msg = 'sp_OAMethod read response failed' goto
eh end
print '7'
exec @hr = sp_OADestroy @obj
return
eh:
exec @hr = sp_OADestroy @obj
Raiserror(@msg, 16, 1)
return
print '8'
USE [db]
GO
DECLARE @return_value int,
@response varchar(8000)
EXEC @return_value = [dbo].[HTTP_POST]
@response = @response OUTPUT
SELECT @response as N'@response'
SELECT 'Return Value' = @return_value
GO