【发布时间】:2021-08-11 11:52:31
【问题描述】:
我正在设置一个我知道可以使用给定凭据的 API 调用。一般来说,我是 C# 和 .NET 的新手,有人告诉我使用 RestSharp 进行 API 调用。什么作为参数传递给 RestClient?我已经尝试过我的本地服务器,但不确定就是这样。
这里是控制器代码:
const string endpoint = "https://api.test.hotelbeds.com/hotel-api/1.0/status";
string signature;
using (var sha = SHA256.Create())
{
long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds / 1000;
Console.WriteLine("Timestamp: " + ts);
var computedHash = sha.ComputeHash(Encoding.UTF8.GetBytes(apiKey + sharedSecret + ts));
signature = BitConverter.ToString(computedHash).Replace("-", "");
}
var client = new RestClient("?");
var request = new RestRequest(endpoint, Method.GET);
request.AddHeader("X-Signature", signature);
request.AddHeader("Api-Key", apiKey);
var response = client.Execute(request);
Debug.WriteLine("this is the response" + response);
return View();
}
【问题讨论】:
标签: c# .net visual-studio