on 2022 Jul 21 6:41 AM
Hi,
We're trying to send the .xlsx file using the CL_HTTP_CLIENT but getting an error 'Bad Request, the .xlsx data is in xstring format.
But when we try to post the data using postman it is getting uploaded, but this data is in binary format. How do we send binary data table using CL_HTTP_CLIENT. Can you please help me out to send the binary data. Appreciate your help. Thank you
data:
lv_url type string,
lv_token_bearer type string,
lv_response type string,
lo_http_client type ref to if_http_client.
check ls_token is not initial.
lv_url = |https://xxxxxxx.sharepoint.com/sites/SiteName/| &&
|_api/web/GetFolderByServerRelativeUrl('Shared Documents')/| &&
|Files/add(url='Test1.xlsx',overwrite=true)|.
call method cl_http_client=>create_by_url
exporting
url = lv_url
importing
client = lo_http_client
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4.
if sy-subrc <> 0.
* raise exception.
endif.
lv_token_bearer = |Bearer | && ls_token-access_token.
lo_http_client->request->set_header_field(
name = 'Accept' "#EC NOTEXT
value = 'application/json;odata=verbose' ).
lo_http_client->request->set_header_field(
name = 'Content-Type' "#EC NOTEXT
value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ).
data: lv_content_length type string.
lv_content_length = xstrlen( xstring_data ).
lo_http_client->request->set_header_field(
name = 'Content-Length' "#EC NOTEXT
value = lv_content_length ).
lo_http_client->request->set_header_field(
name = 'Authorization' "#EC NOTEXT
value = lv_token_bearer ).
lo_http_client->request->set_method('POST').
lo_http_client->request->set_data(
data = xstring_data ).
lo_http_client->send(
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
others = 5 ).
if sy-subrc = 0.
lo_http_client->receive(
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
others = 4 ).
endif.
lv_response = lo_http_client->response->get_cdata( ).
data:
lv_code type i,
lv_reason type string.
lo_http_client->response->get_status(
importing
code = lv_code
reason = lv_reason ).
lo_http_client->close(
exceptions http_invalid_state = 1
others = 2 ).
if lv_code ne 200.
* Raise Exception
endif.
User | Count |
---|---|
68 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.