我可以使用邮递员获取访问令牌,但无法使用 PL/SQL 块。即使我使用相同的客户端 ID 和客户端密码,我也会得到未经授权的回复。请让我知道我做错了什么。我正在研究 oracle 12c。谢谢。
DECLARE
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
l_ClientID varchar2(1000) := 'clientid';
l_ClientSecret varchar2(1000) := 'clientsecret';
l_AuthResponse UTL_HTTP.RESP;
l_AuthRaw VARCHAR2 (32767);
l_AuthReqBody varchar2(2000);
v_url varchar2(2000) := 'http://someurl/oauth/token';
l_ClientCredetial VARCHAR2(1000) := l_ClientID || ':' || l_ClientSecret;
BEGIN
l_AuthReqBody := 'grant_type=client_credentials'|| chr(38) || 'client_id=' || l_ClientID || chr(38) || 'client_secret=' || l_ClientSecret;
-- Set Oracle Wallet, which works fine
http_req := utl_http.begin_request(
v_url ,
'POST',
'HTTP/1.1');
utl_http.set_header (http_req, 'Content-Type','application/x-www-form-urlencoded');
utl_http.write_text (http_req, l_AuthReqBody);
l_AuthResponse := utl_http.get_response(http_req);
utl_http.read_text(l_AuthResponse, l_AuthRaw);
sp_memo_temp('1 l_AuthRaw: '||l_AuthRaw);
UTL_HTTP.end_response (l_AuthResponse);
UTL_HTTP.end_request (http_req);
END;
我只需要使用 OAuth 访问 REST 网络服务,我只需要用我的令牌 utl_http.set_header(l_http_request, 'Authorization', l_token) 设置标头。
罗什尼, 你解决过这个问题吗? 我现在有完全相同的问题。我的代码与您的代码几乎相同,但我得到了 400 错误代码。 谢谢