Continuing the discussion from Http request activitty- binary format body:
Hi,
I’m trying to upload a pdf file using client API. it is working when I try with Postman. it is not working with UiPath Invoke code…
here is the code I’m using which I have taken from Yoichi’s response previously for a similar query…
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
HttpClient client = new HttpClient();
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
{
//byte bytes = File.ReadAllBytes(filepath);
ByteArrayContent content = new ByteArrayContent(bytes);
content.Headers.Add(“content-type”, “application/pdf”);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
HttpResponseMessage response = client.PostAsync(url, content).Result;
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsStringAsync().Result;
// Above three lines can be replaced with new helper method below
// string responseBody = await client.GetStringAsync(uri);
Console.WriteLine(responseBody);
}
catch(HttpRequestException e)
{
Console.WriteLine(“\nException Caught!”);
Console.WriteLine("Message :{0} ",e.Message);
}
I’m always getting the exception caugt message…
Exception Caught!
Message :Response status code does not indicate success: 405 (Method Not Allowed).
I have also tried to use Http Request activity but no luck…Please help