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: 

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

0 Kudos

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,

1 ACCEPTED SOLUTION

0 Kudos

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.

2 REPLIES 2

0 Kudos

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.

0 Kudos

Hi praveen,

I am also trying to do the same thing. Can you please let me know the steps involved.