hidrau
asked on
Http Post send by Store Procedure Help
Hello Guys
I am trying to Post my URL through this store proc but it doesn't work for me.
I'd like to know if it works for you and if not, What I need to do to fix it or maybe you have a better code.
Bellow the HTTP_POST there is my code that I am trying to post it, you can do a test
You can run this test bellow, it should work but it returns all the select NULL
Guys, I also find this link, but I haven't be able to make it work so far.
I thanks a lot for your help
Alex
I am trying to Post my URL through this store proc but it doesn't work for me.
I'd like to know if it works for you and if not, What I need to do to fix it or maybe you have a better code.
Bellow the HTTP_POST there is my code that I am trying to post it, you can do a test
CREATE procedure HTTP_POST( @sUrl varchar(200), @response varchar(8000) out, @error varchar(100) out)
As
Declare
@obj int
,@hr int
,@status int
,@msg varchar(255)
exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
-- 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, 'GET', @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_OAGetProperty @obj, 'status', @status OUT
if @hr <>0 begin set @msg = 'sp_OAMethod read status failed' goto
eh
end
if @status <> 200 begin set @msg = 'sp_OAMethod http status ' +
str(@status) goto eh end
exec @hr = sp_OAGetProperty @obj, 'responseText', @response OUT
if @hr <>0 begin set @msg = 'sp_OAMethod read response failed' goto
eh end
exec @hr = sp_OADestroy @obj
return
eh:
exec @hr = sp_OADestroy @obj
set @error = @msg
return
GO
You can run this test bellow, it should work but it returns all the select NULL
Declare @url varchar(2000)
Declare @res varchar(2000)
Declare @err varchar(2000)
set @url = 'http://wsrescom.com.br/Postagem.asmx/InsertPostagem?id_cliente=12966706000B191&nome=BANCO%20BNP%20PARIBAS%20BRASIL%20S.A.&logradouro=AV%20PRESIDENTE%20JUSCELINO%20KUBITSCHEK&codigo_administrativo=14448769&contrato=9912363819&numero=510&bairro=VILA%20NOVA%20CONCEICAO&cidade=S%C3%83O%20PAULO&uf=SP&cep=04543-000&cartao=70302626&codigo_servico=&ar=0&numero_coleta=0123&data_processamento=05/03/2017&complemento=&referencia=&ddd=&telefone=&email=financeiro@br.bnpparibas.com&valor_declarado=0&item=&desc='
exec HTTP_POST @url, @res, @err
select @res
Select @err
Guys, I also find this link, but I haven't be able to make it work so far.
http://www.vishalseth.com/post/2009/12/22/Call-a-webservice-from-TSQL-(Stored-Procedure)-using-MSXML.aspx
I thanks a lot for your help
Alex
when you run your script, what error messages are you getting?
ASKER
I get the erro http 500
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you still need any further assistance here?
ASKER
thanks Ryan