我正在尝试从SQL Server 2008存储过程向松弛通道发送消息。
DECLARE @obj INT
DECLARE @url varchar (200)
DECLARE @resp varchar (200)
DECLARE @str as varchar(200)
DECLARE @token as varchar(200)
SET @str = 'channel=U015WQQ75RB&text=TestTestTest'
SET @url = 'https://slack.com/api/chat.postMessage'
SET @token = 'Bearer xoxb-MY-TOKEN-HERE'
EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
EXEC sp_OAMethod @obj,'open',NULL,'POST',@url, false
EXEC sp_OAMethod @obj,'setRequestHeader', NULL, 'Authorization' ,@token
EXEC sp_OAMethod @obj,'setRequestHeader', NULL, 'Content-Type', 'application/x-www-form-urlencoded'
EXEC sp_OAMethod @obj, 'send', NULL, @str
EXEC sp_OAGetProperty @obj, 'ok', @resp out
print @resp
EXEC sp_OADestroy @obj
有人可以引导我在这里做错什么吗?我已经为此苦苦挣扎了三天了。
我尝试使用requestbin进行调试,并且所有参数和标头都已从SQL Server发送到Web服务。 但是,当我使用Slack API时,我没有收到Slack API的响应。没错没事。
如果我从浏览器中调用此URL,则会发送消息。 https://slack.com/api/chat.postMessage?token=xoxb-my-token&channel=U015WQQ75RB&text=TestTestTest
我认为我无法以正确的格式发送参数。