Hello everyone,
I am with DB-12.1
When I send an api request with Spanish characters, I receive an error "Invalid UTF-8 middle byte 0x6f \"
The function is as follows:
create or replace FUNCTION NEXMO_ENVIA_MENSAJE_VOZ
(
p_Convenio IN VARCHAR2
, p_Cliente IN VARCHAR2
, TO_HACIA IN VARCHAR2
, FROM_DESDE IN VARCHAR2
, Texto_a_voz IN clob
)
return varchar2
AS
v_url varchar2(100) := 'https://api.nexmo.com/v1/calls/';
v_req utl_http.req;
v_resp utl_http.resp;
v_texto varchar2(32767);
v_texto_a_voz varchar2(4000) := '{
"to": [{ "type": "phone", "number": "56229932496"}],
"from": {"type": "phone", "number": "56989460454"},
"ncco": [{"action": "talk",
"voiceName": "Mia",
"text": "Esta es una prueba para ver si funciona bien en español, Niño, año, acción",
"level" : 1,
"bargeIn" : true
},
{
"action": "input",
"submitOnHash": true,
"timeOut": 10,
"maxDigits" : 1
},
{
"action": "talk",
"text": "Gracias por su respuesta, hasta luego.",
"voiceName": "Mia"
}]
}';
v_texto_a_voz_CONV clob;
BEGIN
-- Defino Wallet = SOLAMENTE DEBE CONTENER EL CERTIFICADO ROOT DE LA AUTORIDAD CERTIFICADORA (CA)
UTL_HTTP.set_wallet('file:/home/oracle/ssl/nexmo', 'xxxxx');
v_req := utl_http.begin_request(url => v_url,
method => 'POST'
);
v_texto_a_voz_CONV := v_texto_a_voz;
-- v_texto_a_voz_CONV := TRANSLATE(v_texto_a_voz_CONV,'áéíóúÁÉÍÓÚñÑ','aeiouAEIOUnN');
-- v_texto_a_voz_CONV := CONVERT(v_texto_a_voz_CONV,'UTF8');
-- Defino Header
utl_http.set_header(v_req, 'Content-Type', 'application/json');
utl_http.set_header(v_req, 'Authorization', 'Bearer <JWT>');
when I activate v_texto_a_voz_CONV: = TRANSLATE (v_texto_a_voz_CONV, 'áéíóúÁÉÍÓÚñÑ', 'aeiouAEIOUnN') ;, it works fine.
Someone has an idea of the solution, your help is greatly appreciated.
Regards
Carlos
utl_http.set_header(v_req, 'Content-Length', length(v_texto_a_voz_CONV));
-- Defino Body
dbms_output.put_line('/' || v_texto_a_voz_CONV || '/');
-- utl_http.set_body_charset(v_req, 'UTF-8');
utl_http.write_text(v_req, v_texto_a_voz_CONV );
v_resp := utl_http.get_response(v_req);
-- loop through the data coming back
begin
loop
utl_http.read_text(v_resp, v_texto, 32766);
dbms_output.put_line(v_texto);
end loop;
exception
when utl_http.end_of_body then
utl_http.end_response(v_resp);
end;
return v_texto;
END NEXMO_ENVIA_MENSAJE_VOZ;
----
Conectando a la base de datos cobrotech@cobrotech-db.aws-NVirginia.
/{
"to": [{ "type": "phone", "number": "56229932496"}],
"from": {"type": "phone", "number": "56989460454"},
"ncco": [{"action": "talk",
"voiceName": "Mia",
"text": "Esta es una prueba para ver si funciona bien en español, Niño, año, acción",
"level" : 1,
"bargeIn" : true
},
{
"action": "input",
"submitOnHash": true,
"timeOut": 10,
"maxDigits" : 1
},
{
"action": "talk",
"text": "Gracias por su respuesta, hasta luego.",
"voiceName": "Mia"
}]
}/
{"type":400,"title":"Bad Request","invalid_parameters":[{"reason":"Invalid UTF-8 middle byte 0x6f\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 6, column: 66]","name":"ncco"}]}
El proceso ha terminado.
Desconectando de la base de datos cobrotech@cobrotech-db.aws-NVirginia.