Razor-pages upload file by HttpClient with credentials

Viewed 62

How can I upload file using HttpClient with credentials? I'm trying to find some example/tutorial, but it's all unclear for me. I want to upload file (image) from the form in Razor-pages on network disc by HttpClient, but I must be able to put my username and password - otherwise it won't work

1 Answers

Yo can use HttpClientHandler class

var handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential(userName, password);
// here your have to pass your handler to HttpClient constructor 
var client = new HttpClient(handler);
Related