aquinn
(Aquinn)
June 1, 2023, 11:50am
1
I have this call;
var options = new RestClientOptions(“http://url ”)
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest(“End Point”, Method.Post);
request.AlwaysMultipartFormData = true;
request.AddFile(“att”, “File path to upload”);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
with the web.api package installed and dependencies of:
restsharp
restsharp.auth
restsharp.auth.oauth
newtonsoft.json
newtonsonft.json.linq
But i am getting these errors:
aquinn
(Aquinn)
June 1, 2023, 11:55am
2
@Anil_G Would you be able to help please?
aquinn
(Aquinn)
June 1, 2023, 11:59am
4
I have read this post youve linked and I cant seem to get it to work, I have this so far
async System.Threading.Tasks.Task MakeRequestAsync()
{
var client = new RestClient(“URL”);
client.Timeout = -1;
var request = new RestRequest(“End point”, Method.Post);
request.AddFile(“att”, “PATHWAY TO FILE”);
IRestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
}
Anil_G
(Anil Gorthi)
June 1, 2023, 12:18pm
5
aquinn:
RestRequest
@aquinn
Please try this
async System.Threading.Tasks.Task MakeRequestAsync()
{
var client = new RestSharp.RestClient("URL");
client.Timeout = -1;
var request = new RestSharp.RestRequest("End point", RestSharp.Method.Post);
request.AddFile("att", "PATHWAY TO FILE");
RestSharp.IRestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
}
cheers
aquinn
(Aquinn)
June 1, 2023, 12:33pm
6
Anil_G:
async System.Threading.Tasks.Task MakeRequestAsync()
{
var client = new RestSharp.RestClient("URL");
client.Timeout = -1;
var request = new RestSharp.RestRequest("End point", RestSharp.Method.Post);
request.AddFile("att", "PATHWAY TO FILE");
RestSharp.IRestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
}
Thank you, Now i am getting this
aquinn
(Aquinn)
June 1, 2023, 12:51pm
8
I am also similarly struggling to find out how to add the file seen here into the HTTP request in UiPath
var options = new RestClientOptions(“URL”)
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestSharp.RestRequest(“end point”, Method.Post);
request.AddHeader(“Content-Type”, “application/zip”);
request.AddParameter(“application/zip”, “file contents here”, ParameterType.RequestBody);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
Anil_G
(Anil Gorthi)
June 1, 2023, 1:21pm
9
@aquinn
Please try this
async System.Threading.Tasks.Task MakeRequestAsync()
{
var client = new RestSharp.RestClient("URL");
client.Timeout = -1;
var request = new RestSharp.RestRequest("End point", RestSharp.Method.POST);
request.AddHeader("Content-Type", "application/zip");
request.AddParameter("application/zip", "file contents here", RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
}
cheers
aquinn
(Aquinn)
June 1, 2023, 1:23pm
10
I will, and do I just put the pathway to the file I am uploading in “file contents here”?
As I am using this to post a file via HTTP request
Thank you so much for your help
aquinn
(Aquinn)
June 1, 2023, 1:54pm
12
I get this error when i put in the pathway
aquinn
(Aquinn)
June 1, 2023, 1:58pm
14
Thank you, now I am getting this when it runs
I am trying to post the file to that end point if that makes sense?
Anil_G
(Anil Gorthi)
June 1, 2023, 1:59pm
15
@aquinn
This looks like an api error
You have to check the api
cheers
aquinn
(Aquinn)
June 1, 2023, 2:02pm
16
My full URL is “http://connect.Easyonline.nl/n1/httpserver?ai=Test&bcxsl=post.xsl&saction=1&id=tst&auth=t5t ”
split into
URL http://connect.Easyonline.nl
and End point - /n1/httpserver?ai=Test&bcxsl=post.xsl&saction=1&id=tst&auth=t5t
and it works in postman
Anil_G
(Anil Gorthi)
June 1, 2023, 2:09pm
17
@aquinn
I believe it needs content in base64 change this line
request.AddParameter("application/zip", Convert.ToBase64String(System.IO.File.ReadAllBytes("FilePath")), RestSharp.ParameterType.RequestBody);
cheers
aquinn
(Aquinn)
June 1, 2023, 2:11pm
18
And this will be able to send a whole .zip folder to the URL?
Anil_G
(Anil Gorthi)
June 1, 2023, 2:12pm
19
@aquinn
Ideally the filepath would be the zip file and converting content to base64 so it should
cheers
aquinn
(Aquinn)
June 1, 2023, 2:14pm
20
it states that the channel still does not exist, but thank you
Anil_G
(Anil Gorthi)
June 1, 2023, 2:17pm
21
@aquinn
If you have the api site please check what this error means may be from there we can take forward
Not sure if it needs any proxy
cheers
1 Like