title: Why am I getting this error in Oauth 2 access token code using PL/SQL?
body: <p>I am able to get the access token using postman but I am not able to using the PL/SQL Block. I get unauthorized back as response even when I use the same client id and client secret. Please let me know what am I doing wrong. I am working on oracle 12c. Thank you.</p>
  
  <pre><code>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;
  </code></pre>