‎2010 Jul 19 9:21 PM
I'm trying to do a HTTP POST via ABAP. The application that I'm posting to does not like the "charset=utf-8" that is in the request. I've been told that I need to remove it. Does anyone know how to do this? I'm not setting this field. SAP is adding this charset automatically.
Here is the request:
POST /hapld/tos/kdwhapltos HTTP/1.1
content-type: multipart/mixed; boundary=BOUNDARY; charset=utf-8
content-length: 2018
host: www.pld-certify.ups.com
user-agent: SAP Web Application Server (1.0;700)
accept-encoding: gzip
sap-trace: 3
--BOUNDARY
Content-type: application/x-www-form-urlencoded
Content-length: 128
AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&ResponseType=application/x-ups-pld&VersionNumber=V4R1&UserId=xxxxxx&Password=xxxxxx
--BOUNDARY
Content-type: application/x-ups-binary
Content-length: 1396
020093 2010071800000006852703500 000000002*AA296007......etc
BOUNDARY
Here is my code:
CALL METHOD cl_http_client=>create
EXPORTING
host = POST_HOST
service = '443'
scheme = '2'
ssl_id = 'ANONYM'
proxy_host = wf_proxy
proxy_service = wf_port
IMPORTING
client = http_client.
http_client->propertytype_logon_popup = http_client->co_disabled.
wf_user = '' .
wf_password = '' .
data: lv_value type string.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_protocol'
value = 'HTTP/1.1'.
CALL METHOD http_client->request->set_header_field( name = '~server_protocol' value = 'HTTP/1.1' ).
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'HOST'
value = POST_HOST.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = POST_URI.
CALL METHOD http_client->request->set_content_type
EXPORTING
content_type = 'multipart/mixed; boundary=BOUNDARY'.
CALL METHOD http_client->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'Accept-Charset'
VALUE = 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'.
CALL METHOD http_client->request->SET_FORMFIELD_ENCODING
EXPORTING
FORMFIELD_ENCODING = http_client->request->CO_ENCODING_URL.
CALL METHOD http_client->request->set_cdata
EXPORTING
data = wf_string
offset = 0
length = rlength.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
CLEAR wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
‎2012 May 10 9:34 PM
‎2014 May 07 1:09 PM
Hello Raimo,
I am also facing similar issue while posting messages via Http adapter Can you please let me know how you cracked this issue
Regards,
Amit
‎2014 Aug 21 1:52 PM
Hi,
I had a similar problem and could resolve it by using APPEND_DATA instead of APPEND_CDATA. Likewise, SET_DATA instead of SET_CDATA might solve the issue for you. The data has to be provided as binary data then.
Regards,
Stefan
‎2016 Mar 07 9:54 AM
Hi,
APPEND_DATA works fine for me.
I use for the String-To-XString-Conversion the following FM:
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = output " variable type string
IMPORTING
buffer = outputx. " variable type xstring
Regards,
Matthias
‎2023 Nov 16 2:42 PM
Hi guys,
following Mattias and Stefan comments, it works for me too - using SET_DATA( ) instead of SET_CDATA( ), converting string to xstring beforehand.
Thanks for sharing!
BR,
Ivaylo
‎2024 Dec 12 5:31 PM
To avoid charset=UTF-8
I am referencing variables from your code for you to better understand, just add below code
CALL METHOD http_client->request->suppress_charset ( supress = abap_true ).
Regards,
Ajinkya Chothave