How to use curl script in UiPath

yes changed as per ur suggestion still this error


Do you added ‘RestSharp’ to imports?

image

Yes i added.
i have to just double click right on restsharp ?
or i have to do something more to add?

i double ckicked and saved
1

Yes, you are looking for RestSharp in the namespace search engine and you double click when the entry appeared in the list.

Add also System.Text to Imports:
image

My namespaces in workflow with C#:

Also declare response in Variables tab As: RestSharp.IRestResponse

And set Argument in C# invoked code arguments:

Important:
After you make the changes, enter the C # code editing by clicking “Edit Code”, then save the code by clicking “OK” for the compiler to validate the data again.

while installing system.text i am getting error.
i guess some package issue is there for me.
kindly suggest me if i am missing something i have installed almost all namespaces as yours

also check this error


@Adrian_Star

I had problems with this package:
image

Solution for you: create a new workflow and rewrite the flow. Include the minimum required namespaces.

Delete from Default for response variable RestResponse:

I’ve prepared C# code for you:

var client = new RestSharp.RestClient(URL);
client.Timeout = -1;
var request = new RestSharp.RestRequest(Method.POST);
var base64authorization =     Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username +":"+password));
request.AddHeader("Authorization", String.Format("Basic {0}", base64authorization));
request.AddHeader("Content-Type", "application/json");
request.AddJsonBody(JsonString);
response = client.Execute(request);

I’m not sure if request.AddJsonBody(JsonString) is suitable.

There was definitely a problem with that: request.Content = new StringContent()

Instead of request.AddJsonBody(JsonString) you can set:

request.RequestFormat = DataFormat.Json;
request.AddBody(JsonString);

Check workflow:
sample.7z (2,6 KB)

Thanks for the help.
this solution worked for me.

1 Like

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