Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Remove charset=utf-8 from HTTP POST

tony_raimo2
Explorer
0 Likes
4,517

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( ).

6 REPLIES 6
Read only

asdasd_asdasd
Active Participant
0 Likes
2,650

Tony, can you share with us how you solved your problem.?

Read only

shivhare
Active Contributor
0 Likes
2,650

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

Read only

Former Member
2,650

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

Read only

0 Likes
2,650

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

Read only

Ivaylo
Explorer
0 Likes
2,650

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

Read only

ajinkyachothave-1
Discoverer
0 Likes
1,923

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