<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Send .xlsx document using CL_HTTP_CLIENT in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575246#M4715519</link>
    <description>&lt;P&gt;Are there any details in HTTP response headers? In successful response in postman you can see there are 29 header fields. You can get them with method response-&amp;gt;get_header_fields( ).&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 06:41:16 GMT</pubDate>
    <dc:creator>Tomas_Buryanek</dc:creator>
    <dc:date>2022-07-27T06:41:16Z</dc:date>
    <item>
      <title>Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaq-p/12575237</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;
  &lt;P&gt;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. &lt;/P&gt;
  &lt;P&gt;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&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2077652-postman1.png" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2077653-postman2.png" /&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;  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/| &amp;amp;&amp;amp;
           |_api/web/GetFolderByServerRelativeUrl('Shared Documents')/| &amp;amp;&amp;amp; 
           |Files/add(url='Test1.xlsx',overwrite=true)|.

  call method cl_http_client=&amp;gt;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 &amp;lt;&amp;gt; 0.
*   raise exception.
  endif.

  lv_token_bearer = |Bearer | &amp;amp;&amp;amp; ls_token-access_token.

  lo_http_client-&amp;gt;request-&amp;gt;set_header_field(
    name  = 'Accept'                                        "#EC NOTEXT
    value = 'application/json;odata=verbose' ).

  lo_http_client-&amp;gt;request-&amp;gt;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-&amp;gt;request-&amp;gt;set_header_field(
    name  = 'Content-Length'                                "#EC NOTEXT
    value = lv_content_length ).

  lo_http_client-&amp;gt;request-&amp;gt;set_header_field(
    name  = 'Authorization'                                 "#EC NOTEXT
    value = lv_token_bearer ).

  lo_http_client-&amp;gt;request-&amp;gt;set_method('POST').

  lo_http_client-&amp;gt;request-&amp;gt;set_data(
    data = xstring_data ).&lt;BR /&gt;
  lo_http_client-&amp;gt;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-&amp;gt;receive(
      exceptions
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        others                     = 4 ).
  endif.

  lv_response = lo_http_client-&amp;gt;response-&amp;gt;get_cdata( ).

  data:
    lv_code           type i,
    lv_reason         type string.

  lo_http_client-&amp;gt;response-&amp;gt;get_status(
    importing
      code   = lv_code
      reason = lv_reason ).

  lo_http_client-&amp;gt;close(
    exceptions http_invalid_state = 1
               others             = 2 ).
  if lv_code ne 200.
*   Raise Exception
  endif.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 05:41:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaq-p/12575237</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2022-07-21T05:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575238#M4715511</link>
      <description>&lt;P&gt;How does your code look like? &lt;/P&gt;&lt;P&gt;What kind of error is it? Is it returned by the sever?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 06:10:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575238#M4715511</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2022-07-21T06:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575239#M4715512</link>
      <description>&lt;P&gt;I think that bad request can mean anything wrong in your request, so you should post your code.&lt;/P&gt;&lt;P&gt;For information, it's very simple for sending xstring containing Excel file in XLSX true format, I guess it's what you did, so better include in your question so that we just confirm that it's good:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;request-&amp;gt;set_data( xstring_xlsx ).
request-&amp;gt;set_content_type( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 07:14:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575239#M4715512</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-07-21T07:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575240#M4715513</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;gabmarian&lt;/SPAN&gt;, &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Appreciate your comment. I have include the test code in the question, the error is from the server. Postman is loading the data in Binary format to process the request, is there way to send the binary table using CL_HTTP_CLIENT. Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 04:50:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575240#M4715513</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2022-07-22T04:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575241#M4715514</link>
      <description>&lt;P&gt;Sorry, made a mistake in my previous comment. I replaced client-&amp;gt; with request-&amp;gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 06:13:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575241#M4715514</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-07-22T06:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575242#M4715515</link>
      <description>&lt;P&gt;Any way we can send the binary table data using CL_HTTP_CLIENT?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 06:06:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575242#M4715515</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2022-07-26T06:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575243#M4715516</link>
      <description>&lt;P&gt;CL_HTTP_CLIENT accepts only xstring. You should convert binary table to xstring. Maybe you have mistake in this conversion? Are you giving correct binary data length to conversion?&lt;/P&gt;&lt;P&gt;EDIT: Few tips - check response header fields to better understand where is the issue. Why is webservice returning error? There is only "Bad request" text in body?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 11:18:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575243#M4715516</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2022-07-26T11:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575244#M4715517</link>
      <description>&lt;P&gt;How do you generate the .xlsx file you are sending?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 05:38:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575244#M4715517</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2022-07-27T05:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575245#M4715518</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;tomas.buryanek&lt;/SPAN&gt;, I tried with correct length of the xstring. The body has only this information " 400 Bad HTTP request####0001ae4a"&lt;/P&gt;&lt;P&gt;Is there any way we can place the excel file.( This xstring is generated using abap2xlsx)&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 05:55:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575245#M4715518</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2022-07-27T05:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575246#M4715519</link>
      <description>&lt;P&gt;Are there any details in HTTP response headers? In successful response in postman you can see there are 29 header fields. You can get them with method response-&amp;gt;get_header_fields( ).&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 06:41:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575246#M4715519</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2022-07-27T06:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575247#M4715520</link>
      <description>&lt;P&gt;Are you sure that the .xlsx file is correct? If you download it from SAPGUI to your desktop will it open in Excel without any issues?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 08:26:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575247#M4715520</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2022-07-27T08:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575248#M4715521</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;tomas.buryanek&lt;/SPAN&gt;, There is not much information in the response header. Please check below response header details.&lt;/P&gt;&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;gabmarian&lt;/SPAN&gt;, This file is generated using abap2xlsx project. We tested downloading it into our local machine and it is working.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2077929-response-header.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 17:59:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575248#M4715521</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2022-07-27T17:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Send .xlsx document using CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575249#M4715522</link>
      <description>&lt;P&gt;  &lt;SPAN class="mention-scrubbed"&gt;srikanthnalluri&lt;/SPAN&gt; Thanks for header fields. I am not 100% sure about this, but you can see you are getting Bad Request from server SAP NetWeaver (it seems). Not from the server you are calling - Sharepoint. That can mean that connection to that outside Sharepoint server did not went through... Try check with Basis or analyse some HTTP logs and analytic t-codes for HTTP connection, trace... (can not help much in this area, sorry).&lt;/P&gt;&lt;P&gt;Your code looks OK and XLSX files is also OK as you tested it on local machine. So it points to HTTP connection from SAP server to outside.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 06:47:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-xlsx-document-using-cl-http-client/qaa-p/12575249#M4715522</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2022-07-28T06:47:38Z</dc:date>
    </item>
  </channel>
</rss>

