[英]How do I set the api key in System.Net.WebClient
What would be the best way for me to set the api key value when deserealizing json from a url. 在从URL中取消实现json时,设置api键值的最佳方法是什么。 The code I am using is below but I don't know how to state the api key
我正在使用的代码如下,但我不知道如何陈述api密钥
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. 密钥的提供者说我应该修改我的客户端以使用标题字段“Authentication-Token”和作为值提供的标记。
You can add headers to requests by adding to the Headers
property of WebClient
. 您可以通过添加到
WebClient
的Headers
属性来向请求添加标头。
using (var webClient = new System.Net.WebClient())
{
webClient.Headers.Add("Authentication-Token", apiKey);
var myTable = webClient.DownloadString(url);
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.