0

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

KnowledgeSeeker
  • 77
  • 1
  • 12
  • HTTP status 5xx means a server problem (4xx would be a client problem). And if you "tried all" then there is no solution. How about talking to the server owner? He should be interested how you manage to get him into HTTP status 500. – AmigoJack Oct 27 '20 at 21:28
  • It looks to me like a client problem because I call 2 web services and it's OK wihout accents and I get error 500 xml malformed when it contains accents. I can reproduce it in soapui when I don't add the encoding expect that UTF-8 resolves the problem in soapui but not in plsql . – KnowledgeSeeker Oct 28 '20 at 09:44

1 Answers1

0

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'))

KnowledgeSeeker
  • 77
  • 1
  • 12