本帖最后由 赵庆明 于 2024-5-24 09:57 编辑
签名实现- public static string GetMd5Hash(string input)
- {
- var md5 = MD5.Create();
- var inputBytes = Encoding.ASCII.GetBytes(input);
- var hashBytes = md5.ComputeHash(inputBytes);
- var sb = new StringBuilder();
- foreach (var t in hashBytes)
- {
- sb.Append(t.ToString("x2"));
- }
- return sb.ToString();
- }
复制代码 参数组装
- private FormUrlEncodedContent GetFormContent(List<KeyValuePair<string, string>>? data = null)
- {
- var requestTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
- var requestToken = GetMd5Hash(requestTime + GetMd5Hash(BtKey));
- if (data == null)
- {
- data = new List<KeyValuePair<string, string>>();
- }
- data.AddRange(new[]
- {
- new KeyValuePair<string, string>("request_time", requestTime),
- new KeyValuePair<string, string>("request_token", requestToken)
- });
- var formContent = new FormUrlEncodedContent(data);
- return formContent;
- }
复制代码
部分C#代码实现
- private readonly string BtPanel;
- private readonly string BtKey;
- static void Main(string[] args)
- {
- var url = BtPanel + "/safe/firewall/get_rules_list";
-
- var handler = new HttpClientHandler();
- handler.ServerCertificateCustomValidationCallback = delegate { return true; };
- var _httpClient = new HttpClient(handler);
-
-
- var response = _httpClient.PostAsync(url, GetFormContent()).Result;
- var result = response.Content.ReadAsStringAsync().Result;
- Console.WriteLine(result);
- }
复制代码
|
|