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
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”
Do you know how to do this in UiPath?
Kind regards
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
marian.platonov:
RestSharp.Authenticators
I have imported the namespace
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.
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
system
(system)
Closed
February 10, 2023, 12:16pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.