Skip to Content

Unable to post json data to web service API through POST method - MULTIPART/FORM-DATA

Hello all,

i am trying to Post Json format data to other application using Webservice Call.

1. get Token

2. Based on token need to post data.

i am able to get the token and also able to post using that.

here the problem is My response after posting data is 200 & (success : TRUE)

But when i went and see the application only file is appearing not the data.

If i do the same thing using Post Man , i can see data there.

Here is my code snippet,

Plesae suggest something....

data : lv_url type string value 'https://XXXXXXXXXX?transformation=JSON Ewaybill (Standard)-1.03'.


cl_http_client=>create_by_url(
exporting
url = lv_url " Logical destination (specified in function call)
importing
client = l_http_client " HTTP Client Abstraction
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4
).

l_http_client->request->set_method( if_http_request=>co_request_method_post ).
l_http_client->request->set_version( if_http_request=>co_protocol_version_1_1 ).

call method l_http_client->request->set_header_field
exporting
name = 'HOST'
value = 'live.encomply.com'.

call method l_http_client->request->set_header_field
exporting
name = 'Authorization'
value = ls_tkn_v.

call method l_http_client->request->set_header_field
exporting
name = 'app-id'
value = 'envoice'.

call method l_http_client->request->set_content_type
exporting
content_type = 'multipart/form-data'.

*********************************Body
multipart = l_http_client->request->add_multipart( ).

multipart->set_header_field(
name = if_http_header_fields=>content_disposition
value = 'form-data; name="transformation"'
).

* multipart->suppress_content_type( ).

multipart->set_cdata(
data = 'JSON Ewaybill (Standard)-1.03'
).

multipart = l_http_client->request->add_multipart( ).

g_file1_cont = jsondata. "contains data in json format

vari = 'form-data; name="E-waybill-Json"; filename="'.
concatenate vari ex '"' into name.

g_file1_form_data = name .

multipart->set_header_field(
name = if_http_header_fields=>content_disposition
value = g_file1_form_data
).

multipart->set_content_type( 'application/json' ).

multipart = l_http_client->request->add_multipart( ).

lv_len = strlen( jsondata ).

multipart->set_cdata(
data = g_file1_cont
offset = 0
length = lv_len ). "01|XXXXXXXXXXX.... sep: cl_abap_char_utilities=>cr_lf


"STEP-4 : SEND HTTP REQUEST
call method l_http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2.

"STEP-5 : GET HTTP RESPONSE
call method l_http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.

"STEP-6 : Read HTTP RETURN CODE
call method l_http_client->response->get_status
importing
code = l_http_status_code
reason = l_status_text.

data lv_result2 type string.

lv_result2 = l_http_client->response->get_cdata( ).

Please hep me...

Regards,

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Apr 01, 2019 at 10:45 AM

    Solved.

    When i send data to application it is receiving as charset/utf-8( i am not setting it ) which application won't supports,so they have added that functionality now the application can able to load the data.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.