HTTP Request - Binary Body Format

Hi
I want to attach a zip file using API. TO do this I need a zip file in binary format. This is how it looks in Postman
image

I tried to convert file using: Convert.ToBase64String(File.ReadAllBytes (“FilePath”))

And pass it in Options of HTTP Request:
Body: FileText
Body Format: “application/binary”

image

Do you know how to do this in UiPath?

Kind regards

Check this example https://uipath-survey.secure.force.com/CaseView/articles/Knowledge/How-to-use-HTTP-Request-activity-to-update-a-Klipfolio-Data-Source-Using-A-CSV-File?lang=en_US and adapt it based on your case.

Also, check this example Posting Zip files with HTTP Request - #2 by manderss

Hi,

Thank you for those links

I tried to use C# code but without success
I have to changed it because I use simple authentication not bearer token.

I get the following error:

Do you know what is causing the error?

It seems that you need to try to import the RestSharp.Authenticators namespace to recognize HttpBasicAuthenticator

That namespace should be present in the RestSharp dependency.

Reference: restsharp - What is wrong with a HttpBasicAuthenticator - Stack Overflow

I have imported the namespace
image

I changed the code a little
var client = new RestSharp.RestClient(postEndpoint);
client.Authenticator = new HttpBasicAuthenticator(“UserAdam”, “PolskaPany1410”)’
client.Timeout = -1;
var request = new RestSharp.RestRequest(RestSharp.Method.POST);
request.AddHeader(“Content-Type”, “application/zip”);
request.AddParameter(“application/zip”, System.IO.File.ReadAllBytes(filePath), RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = client.Execute(request);
ResponseContent = response.Content.ToString();

Now I have no error but nothing happens after code is process. Attachment is not uploaded and I receive empty response.
image

I get the error Message from response.
ResponseContent = response.ErrorMessage.ToString();

It is the following:
“The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.”

This is an internal network error.

Check these solutions:

  • Upgrade windows machine to the latest patch

  • If the Rest application is having an SSL certificate, you need to trust the SSL sign self-certificate first then only you can able to connect IIS SSL - How to Trust a Self Signed Certificate - YouTube

  • Try to disable the certificate verification in your machine or not verify the certificate in your custom code

@marian.platonov thank you for your help.

Code work properly now. I attach the code below:

System.Net.ServicePointManager.ServerCertificateValidationCallback =
(sender, cert, chain, sslPolicyErrors) => true;

var client = new RestSharp.RestClient(postEndpoint);
client.Authenticator = new HttpBasicAuthenticator(“UserAdam”, “TopSikret”);
client.Timeout = -1;
var request = new RestSharp.RestRequest(RestSharp.Method.POST);
request.AddHeader(“Content-Type”, “application/zip”);
request.AddHeader(“Content-Disposition”, “attachment;filename=Witcher3.zip”);
request.AddParameter(“application/zip”, System.IO.File.ReadAllBytes(filePath), RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = client.Execute(request);
ResponseContent = response.Content.ToString();

1 Like

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