Reputation: 169
I have to get the response headers of my "apex_web_service.make_rest_request" request.
I know that it was possible with the "UTL_HTTP" package, as documented here: https://docs.oracle.com/database/121/ARPLS/u_http.htm#BHAHDHHB
But how can I do this with "apex_web_service"? Is it even possible, as I can't find it in this documentation? http://docs.oracle.com/database/121/AEAPI/apex_web_service.htm#AEAPI537
Thanks in advance for your answer(s)!
Upvotes: 6
Views: 10727
Reputation: 41
If you want the HTTP response code , use:
apex_web_service.g_status_code
Upvotes: 4
Reputation: 169
Ok I found it now. The answer can be found here: http://docs.oracle.com/database/121/AEAPI/apex_web_service.htm#AEAPI1933
There is no such thing as a "get_Header()" or something like that. You set your headers and send the request (here example code):
--Set Request Headers
apex_web_service.g_request_headers(1).name := 'Authorization';
apex_web_service.g_request_headers(1).value := '[MY API TOKEN]';
apex_web_service.g_request_headers(2).name := 'Content-Type';
apex_web_service.g_request_headers(2).value := 'application/json';
apex_web_service.g_request_headers(3).name := 'Content-Length';
apex_web_service.g_request_headers(3).value := '[CONTENT LENGTH IN BYTES OF REQUEST BODY]';
l_lcResult := apex_web_service.make_rest_request(p_url => 'MY API URL'
,p_http_method => 'POST'
,p_body => 'REQUEST BODY IN JSON FORMAT');
After the request the headers "change" automatically to the response headers. You can get the response headers as followed:
for i in 1.. apex_web_service.g_headers.count loop
l_vcHeaderName := apex_web_service.g_headers(i).name;
l_vcHeaderValue := apex_web_service.g_headers(i).value;
end loop;
If you are searching for a specific response header (like me), you can use this:
--Here we search for the header-field called 'Location'
for i in 1.. apex_web_service.g_headers.count loop
l_vcHeaderName := apex_web_service.g_headers(i).name;
l_vcHeaderValue := apex_web_service.g_headers(i).value;
exit when l_vcHeaderName = 'Location';
end loop;
dbms_output.put_line('Name: ' || l_vcHeaderName);
dbms_output.put_line('Value: ' || l_vcHeaderValue);
Upvotes: 11