Link to home
Start Free TrialLog in
Avatar of Lr150561
Lr150561

asked on

http 407 status error with SQL stored proc

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&refresh_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-urlencoded'
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
Avatar of Jason clark
Jason clark
Flag of United States of America image

This is a proxy authentication related issue with SQL Server reporting services.
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial