Is there any way to get a JSON "result" using Oracle’s utl_http package

Asked

Viewed 117 times

0

Is there any way to get a JSON "result" using the package utl_http oracle ?

The status code of the following routine returns 200 but would also return a "Sponse" with a JSON conformation, an inscription ID.

{
"id": 11111
...
} 

I can’t read this "Answer" by utl_http.get_response.

Is there any/Function method to get this return (JSON) ?

I can’t reproduce for security and secrecy.

Basic code example (as far as possible)

And a CRUD registration API.

Rinclusion.xxxx is just the cursor/field that operates the thing.

The question is : As in Oracle (utl_http) get the JSON return ?

declare
  url varchar2(4000) := 'https://....';
  VS_TOKEN VARCHAR2(42) := '.......';  
  req utl_http.req;
  res utl_http.resp;
  
begin
  content varchar2(4000);
  content :=  '{                                                         '||
                  '"name": "'||RInclusao.NOME||'",                           '||                   
                  '"mail": "'||RInclusao.EMAIL||'",                          '||                   
                  '"dateBirth": "'||RInclusao.DATA_NASC||'",                 '||                 
                  '"additionalInformation": "'||RInclusao.DADO_ADICIONAL||'" '||
                  '}                                                         ';
                        
      req := utl_http.begin_request(url, 'POST');
      utl_http.set_header(req, 'Content-Type', 'application/json'); 
      utl_http.set_header(req, 'Content-Length', length(content));  
      utl_http.set_header(req, 'token', VS_TOKEN);  
      
      utl_http.write_text(req, content);  
      
      res := utl_http.get_response(req);  
      
      dbms_output.put_line('HTTP response status code: ' || res.status_code);
      dbms_output.put_line('HTTP response reason phrase: ' || res.reason_phrase);
end;

1 answer

0

There wasn’t much mystery add

res := utl_http.get_response(req);  
 
FOR i IN 1..utl_http.get_header_count(res) LOOP
        if nome = '"id"'  Then
          VS_ID := valor;
          exit;
        end if;
      END LOOP;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.