<?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: Attachments2 using HttpClient and C# in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13865201#M4883530</link>
    <description>Hi ANKIT. The same error with .NET httpClient. Based on Fiddler and Service Layer: POST /b1s/v1/Attachments2 HTTP/1.1 Host: mycompany.com:50000 Cookie: B1SESSION=5412064e-71c4-11ef-8000-12c57281de91; ROUTEID=.node4 Accept-Encoding: gzip, deflate Content-Type: multipart/form-data; boundary=c86cf448-3c24-4769-bcb5-fb30989a83d7 Content-Length: 214. Sincerely Jorge.</description>
    <pubDate>Fri, 13 Sep 2024 11:51:29 GMT</pubDate>
    <dc:creator>Jorgedotnet</dc:creator>
    <dc:date>2024-09-13T11:51:29Z</dc:date>
    <item>
      <title>Attachments2 using HttpClient and C#</title>
      <link>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaq-p/13864323</link>
      <description>&lt;P&gt;Hi. Based on&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Postman tool &lt;STRONG&gt;OK&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;.NET B1SLayer &lt;STRONG&gt;OK&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;.NET System.Net.Http.HttpClient &lt;STRONG&gt;Failed&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Assuming that the &lt;STRONG&gt;login&lt;/STRONG&gt; has been previously performed with the&amp;nbsp;&lt;STRONG&gt;SAPclient &lt;/STRONG&gt;object. The &lt;STRONG&gt;Attachments2&lt;/STRONG&gt; method doesn't work with &lt;U&gt;HttpClient&lt;/U&gt; in C#. Please see:&lt;/P&gt;&lt;P&gt;var res = "";&lt;BR /&gt;var content = new MultipartContent();&lt;BR /&gt;var outputFile = new StreamContent(new MemoryStream(File.ReadAllBytes("C:\\Users\\Jorge\\Postman\\files\\helloworld.txt)));&lt;/P&gt;&lt;P&gt;outputFile.Headers.Add("Content-Disposition", $"form-data; name=\"files\"; filename=\"helloworld.txt\"");&lt;BR /&gt;outputFile.Headers.Add("Content-Type", "application/octet-stream");&lt;BR /&gt;content.Add(outputFile);&lt;BR /&gt;var boundary = content.Headers.ContentType!.Parameters.First(o =&amp;gt; o.Name.Equals("boundary", StringComparison.OrdinalIgnoreCase));&lt;BR /&gt;boundary.Value = boundary.Value!.Replace("\"", string.Empty);&lt;/P&gt;&lt;P&gt;var response = await &lt;STRONG&gt;SAPclient&lt;/STRONG&gt;.PostAsync("&lt;A href="https://mycompany.com:50000/b1s/v1/Attachments2" target="_blank" rel="noopener"&gt;https://mycompany.com:50000/b1s/v1/Attachments2&lt;/A&gt;", content);&lt;BR /&gt;if (response.IsSuccessStatusCode == true &amp;amp;&amp;amp; response.StatusCode == HttpStatusCode.Created)&lt;BR /&gt;{&lt;BR /&gt;Attachments2Response? resA = await response.Content.ReadFromJsonAsync&amp;lt;Attachments2Response&amp;gt;();&lt;BR /&gt;res = resA!.AbsoluteEntry.ToString();&amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;The Response:&amp;nbsp;StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:&lt;BR /&gt;{&lt;BR /&gt;Date: Thu, 12 Sep 2024 20:46:02 GMT&lt;BR /&gt;Server: Apache/2.4.54 (Unix)&lt;BR /&gt;DataServiceVersion: 3.0&lt;BR /&gt;Vary: Accept-Encoding&lt;BR /&gt;Connection: close&lt;BR /&gt;Transfer-Encoding: chunked&lt;BR /&gt;Content-Type: application/json;charset=utf-8&lt;BR /&gt;}}&lt;/P&gt;&lt;P&gt;Why and how to fix it?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Jorge&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2024 20:58:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaq-p/13864323</guid>
      <dc:creator>Jorgedotnet</dc:creator>
      <dc:date>2024-09-12T20:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Attachments2 using HttpClient and C#</title>
      <link>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13864763#M4883448</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A class="" href="https://community.sap.com/t5/user/viewprofilepage/user-id/1695397" target="_self"&gt;&lt;SPAN class=""&gt;Jorgedotnet,&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Can you use&amp;nbsp;&lt;STRONG&gt;Fiddler&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;tool to get the request (including all headers) which is being sent to Service Layer to process?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;In the past, we have observed that&amp;nbsp;&lt;STRONG&gt;Expect: 100-continue&lt;/STRONG&gt;&amp;nbsp;header is contained in the request which is not supported by Service Layer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;If it is the case,&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;please add&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;httpClient.DefaultRequestHeaders.ExpectContinue = false;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in the code and check the issue again.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Kind regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;ANKIT CHAUHAN&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;SAP Business One Support&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2024 07:11:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13864763#M4883448</guid>
      <dc:creator>ANKIT_CHAUHAN</dc:creator>
      <dc:date>2024-09-13T07:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Attachments2 using HttpClient and C#</title>
      <link>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13865201#M4883530</link>
      <description>Hi ANKIT. The same error with .NET httpClient. Based on Fiddler and Service Layer: POST /b1s/v1/Attachments2 HTTP/1.1 Host: mycompany.com:50000 Cookie: B1SESSION=5412064e-71c4-11ef-8000-12c57281de91; ROUTEID=.node4 Accept-Encoding: gzip, deflate Content-Type: multipart/form-data; boundary=c86cf448-3c24-4769-bcb5-fb30989a83d7 Content-Length: 214. Sincerely Jorge.</description>
      <pubDate>Fri, 13 Sep 2024 11:51:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13865201#M4883530</guid>
      <dc:creator>Jorgedotnet</dc:creator>
      <dc:date>2024-09-13T11:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Attachments2 using HttpClient and C#</title>
      <link>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13865209#M4883533</link>
      <description>Hi a suggestion: Can you please reproduce this code on your side. Anything please feel free to contact me. Thanks. Jorge</description>
      <pubDate>Fri, 13 Sep 2024 11:58:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/attachments2-using-httpclient-and-c/qaa-p/13865209#M4883533</guid>
      <dc:creator>Jorgedotnet</dc:creator>
      <dc:date>2024-09-13T11:58:59Z</dc:date>
    </item>
  </channel>
</rss>

