Application Development 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: 

Differences between HTTP_POST and CL_HTTP_CLIENT

Former Member
0 Kudos
822

I use function module HTTP_POST from ABAP to send a request to an external server via HTTPS URL. This works fine I get a response status back of 200 and the external server processed the request and I get a correct response in the body of the response.

When I try and replicate this using the newer method cl_http_client . I get a response status back of 200 but the external server can't process the request and doesn't return the expected body response.

The call to HTTP_POST which works is as below:

The only header request I have to create is Content-type:

All the others are created automatically by the function module

CALL FUNCTION 'HTTP_POST'

ABSOLUTE_URI = url

REQUEST_ENTITY_BODY_LENGTH = l_length

BLANKSTOCRLF = 'X'

IMPORTING

STATUS_CODE = l_status_code

STATUS_TEXT = l_status_text

RESPONSE_ENTITY_BODY_LENGTH = l_length_response

TABLES

REQUEST_ENTITY_BODY = GT_REQUEST_ENTITY_BODY

RESPONSE_ENTITY_BODY = GT_RESPONSE_ENTITY_BODY

RESPONSE_HEADERS = GT_RESPONSE_HEADERS

REQUEST_HEADERS = GT_REQUEST_HEADERS

When I try and replicate this call using cl_http_client

I disable the compress.

l_http_client->propertytype_accept_compress = l_http_client->co_disabled.

<b>How do I replicate the BLANKSTOCRLF = 'X' in the HTTP_POST function module?</b>

The headers that I have to create are now Content-type and Content-length.

when SAP creates the HTTP request it converts these to all lower case e.g. content-type and content-length. Is there anyway I can stop this from happening.

Thanks,

1 ACCEPTED SOLUTION

athavanraja
Active Contributor
0 Kudos
143

when using cl_http_client

call method cl_http_client=>create

exporting

host = 'www.webservicex.net'

service = '80'

scheme = '1'

proxy_host = wf_proxy

proxy_service = wf_port

importing

client = http_client.

the scheme has to be 2 to tell it that is https

and for setting content type and length the code would be something like below.

call method http_client->request->set_header_field

exporting

name = 'Content-Type'

value = 'text/xml; charset=utf-8'.

call method http_client->request->set_header_field

exporting

name = 'Content-Length'

value = txlen.

Regards

Raja

1 REPLY 1

athavanraja
Active Contributor
0 Kudos
144

when using cl_http_client

call method cl_http_client=>create

exporting

host = 'www.webservicex.net'

service = '80'

scheme = '1'

proxy_host = wf_proxy

proxy_service = wf_port

importing

client = http_client.

the scheme has to be 2 to tell it that is https

and for setting content type and length the code would be something like below.

call method http_client->request->set_header_field

exporting

name = 'Content-Type'

value = 'text/xml; charset=utf-8'.

call method http_client->request->set_header_field

exporting

name = 'Content-Length'

value = txlen.

Regards

Raja