I wanted to ask how it is possible to change the URL encoding (from ISO-8859-1 to UTF-8) for a POST request.
Now my code is as follows:
cl_http_client=>create_by_url(
EXPORTING
url = lc_url
IMPORTING
client = lr_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
IF sy-subrc <> 0.
MESSAGE e020(rest_core_texts).
EXIT.
ENDIF.
lr_client->request->set_method( method = if_http_entity=>co_request_method_post ).
lr_client->request->set_content_type( content_type = 'text/plain; charset=utf-8' ).
lr_client->request->set_form_field( name = 'sUsername' value = lc_uname ).
Etc..
CALL METHOD lr_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_invalid_timeout = 3
http_processing_failed = 4
OTHERS = 5.
IF sy-subrc NE 0.
MESSAGE i400(sclnt_http).
EXIT.
ENDIF.
One of the form fields in the POST request contains the name of the person and those names might contain german umlaute (ä,ö,ü). The resulting URL is then encoded using an ISO codepage instead of UTF and the external system expects it to be encoded in UTF.
The result is that the external system stores the name the wrong way (e.g. Gr%e4%df) because the URL is encoded using ISO-8859-1 instead of UTF-8.
This is most likely caused by the fact that the system uses ISO-8859-1 by default (Table: TCP0C).
Now, I have tried transforming the variable holding the name using the class CL_ABAP_CODEPAGE from string to xstring and then vice versa as there is no method to directly transform a string variable to a different code page.
Unfortunately this has not yielded any success.
My second guess was to try to transform the http request body into UTF but I didn't find any suitable method nor function module which I could use.
Any suggestion would be much appreciated!
EDIT:
- The system is a non-Unicode system.
- The system codepage is ISO-8859-1.
lr_client->request->set_formfield_encoding( formfield_encoding = lr_client->request->CO_ENCODING_URL ).? - Sandra Rossi