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 2000 Forums
 SQL Server Development (2000)
 Http Post from Sql Server 2000

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-22 : 08:38:46
Papak writes "CREATE procedure dbo.http_post
@sUrl varchar(200), -- URL to post
@xmlDoc varchar(4000), -- XML Data to Post
@response varchar(2000) out

As
Declare
@obj int,
@hr int,
@status int,
@msg varchar(255)

exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @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, 'POST', @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, @xmlDoc
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
Raiserror(@msg, 16, 1)
return


This is the stored procedure I am using to post XML data to another XML server. The problem is server expecting data to be assigned in a variable. How to declare and assign values from Sql Server 2000?"
   

- Advertisement -