Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

REST call fails because of header Proxy-Connection: Keep-Alive

Tom vd DuinFeb 27 2025 — edited Feb 27 2025

Hi all,

I'm trying to do a POST call to the Deepl translation api, using the REST data sources feature in APEX, but I can't get it to work. Whatever I try, it always fais with error 502 Bad Gateway. After some digging, I've found out, that APEX always add a header: Proxy-Connection: Keep-Alive to a request. However, I don't have a proxy set up in Oracle and/or APEX: I've checked the instance settings and the application settings.

For starters, I have a working curl command (executed from my local machine and from the database server):

curl --header "Content-Type: application/json" --data "{\"text\":[\"Good morning\"],\"target_lang\":\"NL\",\"source_lang\": \"EN\"}" https://api-free.deepl.com/v2/translate?auth_key=~~~~

Response: {"translations":[{"detected_source_language":"EN","text":"Goedemorgen"}]}

When I m,ake the following call to apex_web_service:

declare
 lv_response clob;
begin
 apex_web_service.set_request_headers(
     p_name_01  => 'Content-Type'
   , p_value_01 => 'application/json'
   , p_name_02  => 'User-Agent'
   , p_value_02 => 'APEX'
   , p_reset    => true
   , p_skip_if_exists => true
   );
 lv_response := apex_web_service.make_rest_request (
   p_url                   => 'https://api-free.deepl.com/v2/translate?auth_key=~~~~~~'
 , p_http_method           => 'POST'
 , p_body                  => '"{"text":["Good morning"],"target_lang":"NL","source_lang": "EN"}"'
 );
 dbms_output.put_line(lv_response);
end;

I got this response:

<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>nginx</center></body></html>

Digging into the APEX logs, I see:

begin_request p_url=>https://api-free.deepl.com/v2/translate?auth_key=~~~~~~,p_method=>POST,p_proxy_override=>,p_transfer_timeout=>180,p_https_host=>,p_wallet_path=> 
Loading instance wallet 
set_proxy p_url=>https://api-free.deepl.com/v2/translate?auth_key=~~~~~~,p_proxy_override=> 
restore_proxy 
set_header Proxy-Connection: Keep-Alive 
set_header Content-Length: 66 
set_header Content-Type: application/json 
set_header User-Agent: APEX 
body: "{"text":["Good morning"],"target_lang":"NL","source_lang": "EN"}" 
HTTP response 502 - Bad Gateway

I tried adding a header: Proxy-Connection: close, but in the debug, it's added after the set_header User-Agent: APEX line, and the outcome is the same.

If I try the above curl command (on my local machine) and add the header Proxy-Connection: Keep-Alive to it, it gives the same response:

curl --header "Content-Type: application/json" --header "Proxy-Connection: Keep-Alive" --data "{\"text\":[\"Good morning\"],\"target_lang\":\"NL\",\"source_lang\": \"EN\"}" https://api-free.deepl.com/v2/translate?auth_key=~~~~~~

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

What can I do, to prevent APEX adding this header?

Thanks for the answers!

Regards,

Tom

Comments
Post Details
Added on Feb 27 2025
2 comments
269 views