Search code examples
plsqlutf-8character-encodingwebservice-clientfrench

UTL_HTTP and french accents


I try to call a web service using the package UTL_HTTP, it works but I have an issue with french accents( 'é' and 'è') , the UTF-8 is not working .

        CONTENT :=  '{
        "metier": {
        "REF_CONTRAT": "'||ref_contrat||'",
        "ID_HISTO": "'||id_histo||'",
        "ID_OBJ_DECLENCHEUR": "'||ID_OBJ_DECLENCHEUR||'",
        "TYPE_OBJ_DECLENCHEUR": "'||type_obj_declencheur||'",
        "ID_SCENARIO_INSTANCIE": "'||ID_SCENARIO_INSTANCIE||'",
        "ID_SCENARIO": "'||id_scenario||'",
        "ID_SMS": "'||id_sms||'",
        "REPONSE_RECUE": "'||reponse_recue||'",
        "ACTION": "'||ACTION||'",
        "TYPE_ACTION": "'||TYPE_ACTION||'"
      }
    }'; 
   -- V_URL:=UTL_URL.ESCAPE(V_URL,FALSE,'UTF-8');
UTL_HTTP.SET_BODY_CHARSET('UTF-8');
REQ := UTL_HTTP.BEGIN_REQUEST(V_URL, V_METHODE,' HTTP/1.1');
UTL_HTTP.SET_HEADER(REQ, 'user-agent', 'mozilla/4.0');
-- UTL_HTTP.SET_HEADER(REQ, 'content-type', V_CONTENT_TYPE);
UTL_HTTP.SET_HEADER(REQ, 'content-type','application/json; charset="UTF-8"');
utl_http.set_header(req, 'Content-Length', lengthB(content));
UTL_HTTP.SET_HEADER(REQ,'Authorization',V_AUTHORIZATION);
UTL_HTTP.WRITE_TEXT(REQ, CONTENT);
/* UTL_HTTP.WRITE_RAW (R => REQ,
data => UTL_RAW.CAST_TO_RAW(CONTENT)); */

I have error 500 as a response. any idea please ? I tried all what I found on the internet but it's not working


Solution

  • The problem was that length doesn't give the right length when the question contains combined characters ; é was counted as 1 byte instead of 2 so it worked when I converted the request to AL32UTF8 : length(Convert(CONTENT,'AL32UTF8'))