Issue with sending Http post request

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:
image

@Anil_G Would you be able to help please?

@aquinn

  1. For all the type or namespace and ambiguous errors please use full name space eg: Restsharp.RestClientoptions
  2. For the Await error we have to enclose in async method.I am referring to same post again
    Issue using invoke code API - #5 by Anil_G

cheers

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);

}

@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

Thank you, Now i am getting this

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);

@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);
}

image

cheers

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

Yes please

cheers

I get this error when i put in the pathway

@aquinn

instead of \ use \\

cheers

Thank you, now I am getting this when it runs

image

I am trying to post the file to that end point if that makes sense?

@aquinn

This looks like an api error

You have to check the api

cheers

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

@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

And this will be able to send a whole .zip folder to the URL?

@aquinn

Ideally the filepath would be the zip file and converting content to base64 so it should

cheers

it states that the channel still does not exist, but thank you

@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