How do I set the api key in System.Net.WebClient
12,652
You can add headers to requests by adding to the Headers
property of WebClient
.
using (var webClient = new System.Net.WebClient())
{
webClient.Headers.Add("Authentication-Token", apiKey);
var myTable = webClient.DownloadString(url);
...
}
Author by
Nate
Updated on June 10, 2022Comments
-
Nate almost 2 years
What would be the best way for me to set the api key value when deserealizing json from a url. The code I am using is below but I don't know how to state the api key
using (var webClient = new System.Net.WebClient()) { var myTable = webClient.DownloadString(url); var deserealizedTable = JsonConvert.DeserializeObject<MyClass>(myTable); }
The providers of the key said I should modify my client to use a header-field "Authentication-Token" with the token that was provided as the value.