根据https://www.mysalemarketplace.com/docs/#orders中API的文档:
curl "/v1/orders/new/"
-H "Authorization: Bearer XyZAlexYustasu::NeSHarit00Etot42klyuch"
想用WebClient去获取新的订单:
using (WebClient webClient = new WebClient())
{
string path = @"https://cdn.mysalemarketplace.com/v1/orders/new/";
string token = "XyZAlexYustasu::NeSHarit00Etot42klyuch";
webClient.Headers.Add(HttpRequestHeader.Authorization, string.Format("Bearer {0}", token));
byte[] responseData = webClient.DownloadData(path);
string result = Encoding.UTF8.GetString(responseData);
return result;
}
结果返回403 Forbidden,提示“没有权限访问”,
换成正式的token
wclient.Headers.Add("Authorization", "Bearer eyJhbGciOiJIU.........8Kn56fDXWh-lA");
也是一样的错误。
请问:如何用WebClient调用带有Bearer Token的REST API? 谢谢!
(也想用HttpClient试试)