Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 http post

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-01-21 : 12:50:25
i have the following sql
i think it's working but i need to pass the url and the data separately
can anyone guide me with what to change?


CREATE procedure [dbo].[HTTP_POST]
( @sUrl varchar(2000)
, @response varchar(8000) output
, @status int output )
As

Declare @obj int
declare @hr int

exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
-- exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
if @hr <> 0 begin
set @status = -1
set @response = 'sp_OACreate MSXML2.ServerXMLHttp.3.0 failed'
return
end

exec @hr = sp_OAMethod @obj, 'open', NULL, 'POST', @sUrl, false
if @hr <>0 begin
set @status = -2
set @response = 'sp_OAMethod Open failed'
exec @hr = sp_OADestroy @obj
return
end

exec @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type',
'application/x-www-form-urlencoded'
if @hr <>0 begin
set @status = -3
set @response = 'sp_OAMethod setRequestHeader failed'
exec @hr = sp_OADestroy @obj
return
end

exec @hr = sp_OAMethod @obj, send, NULL, ''
if @hr <>0 begin
set @status = -4
set @response = 'sp_OAMethod Send failed'
exec @hr = sp_OADestroy @obj
return
end

exec @hr = sp_OAGetProperty @obj, 'status', @status OUT
if @hr <>0 begin
set @status = -5
set @response = 'sp_OAMethod read status failed'
exec @hr = sp_OADestroy @obj
return
end

if @status <> 200 begin
set @response = 'sp_OAMethod http status ' + cast(@status as varchar(20) )
exec @hr = sp_OADestroy @obj
return
end

/*
declare @len int
set @len = len(@sUrl)
exec @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', @len
if @hr <>0 begin
set @status = -3
set @response = 'sp_OAMethod setRequestHeader failed'
exec @hr = sp_OADestroy @obj
return
end
*/

exec @hr = sp_OAGetProperty @obj, 'responseText', @response OUT
if @hr <>0 begin
/* set @status = -6*/
set @response = 'sp_OAMethod read response failed'
exec @hr = sp_OADestroy @obj
return
end

exec @hr = sp_OADestroy @obj
return

   

- Advertisement -