Http request activitty- binary format body

the api im using accepts image file upload in binary format (see postman screenshot below)

how do i do this using HTTP Request activity in uipath?

Hi,

I asked similar question to UIPath guys 2 years ago, however the answer was “HTTP request activity doesn’t support octet-stream request” and showed me workaround code.
The latest version might be able to do it, but I’ll share it as the following.


  1. add the “System.Net.Http” package in the package manager
  2. Use the “Invoke Code” activity with C#
  // HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
  HttpClient client = new HttpClient();
  // Call asynchronous network methods in a try/catch block to handle exceptions.
  try	
  {
	 ByteArrayContent content = new ByteArrayContent(bytes);
	 content.Headers.Add("content-type", "application/octet-stream");
	 HttpResponseMessage response = client.PostAsync(url, content).Result;
     response.EnsureSuccessStatusCode();
     string responseBody = response.Content.ReadAsStringAsync().Result;
     // Above three lines can be replaced with new helper method below
     // string responseBody = await client.GetStringAsync(uri);

     Console.WriteLine(responseBody);
  }
  catch(HttpRequestException e)
  {
     Console.WriteLine("\nException Caught!");	
     Console.WriteLine("Message :{0} ",e.Message);
  }

Note that this code is a minor tweak of the Microsft Docs Sample.
The arguments to define are bytes which is an Array<Byte> and url which is a string .


Hope this helps you.

Regards,

3 Likes

thanks a lot

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.