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
Lr150561Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason clarkDBA FreelancerCommented:
This is a proxy authentication related issue with SQL Server reporting services.
MlandaTCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTTP Protocol

From novice to tech pro — start learning today.