Reputation: 93
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.
Upvotes: 4
Views: 16517
Reputation: 79511
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);
...
}
Upvotes: 7