1
有沒有辦法使用sp_OACreate 'WinHttp.WinHttpRequest.5.1'
發佈數據使用SQL Server 2008r2和授權標頭,與承載和jwt令牌?下面的代碼不起作用,但希望概述我想要做的事情。獲取401,但在提琴手令牌作品:有沒有辦法使用帶授權標頭的sp_OACreate,使用承載和jwt令牌?
set @body = '{
"id": "73135",
"Objectives": [{
"objt": "blah",
"comment": "blah",
"type": "blah",
"index": "blah",
"state": "blah"
}]
}'
exec @hr = sp_OACreate 'WinHttp.WinHttpRequest.5.1', @obj OUT
if @hr <> 0
begin
set @msg = 'sp_OACreate failed'
end
exec @hr = sp_OAMethod @obj, 'open', NULL, 'POST', 'https://myurl/731', false
if @hr <> 0
begin
set @msg = 'sp_OAMethod Open failed'
end
EXEC sp_OAMethod @hr, 'setRequestHeader', NULL, 'Authorization', 'Bearer long.jwt.here'
exec @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type','application/json'
if @hr <> 0
begin
set @msg = 'sp_OAMethod setRequestHeader failed'
end
exec @hr = sp_OAMethod @obj, send, NULL, @body
if @hr <> 0
begin
set @msg = 'sp_OAMethod Send failed'
end
'EXEC @hr = sp_OAMethod將向@obj,發送,NULL,@body '?也許需要'send'。什麼標題需要'https:// myurl/731'?默認情況下,'WinHttpRequest'將'Charset = UTF-8'添加到'Content-Type'(我記得)。嘗試使用'MSXML2.XMLHTTP'而不是'WinHttp.WinHttpRequest.5.1' – gofr1
@ gofr1它得到一個401所以發送是正確的,並且WinHttp.WinHttpRequest.5.1。這個職位沒有越過Oauth。我的直覺是'Authorization:Bearer jwt'語法不正確。它在使用Fiddler標題時有效 – Steve