http 407 status error with SQL stored proc

Lr150561
Lr150561 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jason clarkDBA Freelancer

Commented:
This is a proxy authentication related issue with SQL Server reporting services.
HTTP 407: Proxy authentication required. you need to call setProxy using something like the below
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Obj OUT;
Exec sp_OAMethod @Obj, 'setProxy', '2', 'http://localhost:8888',''
Exec sp_OAMethod @Obj, 'setProxyCredentials', 'user', 'pass'

Open in new window

These will help:
http://www.codeproject.com/Questions/804037/Using-MSXML-from-a-SP-on-SQL
http://stackoverflow.com/questions/29671077/sql-server-web-service-requests-on-fiddler

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial