我正在尝试将支付平台集成到我的Web应用程序中,但查询事务的一个要求是使用get请求将散列值(某些变量)作为标头发送。这就是我的尝试:
string hashcode = "3409877" + "117" + "D3D1D05AFE42AD508";
var hashedBytes = SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(hashcode));
// Get the hashed string.
var hash = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
hash = hash.ToString().ToUpper();
var amount_kobo = Convert.ToInt32(model.TransactionAmount * 100);
string url = "https://sandbox.interswitchng.com/collections/api/v1/gettransaction.json?productid=117&transactionreference=" + model.TransactionReference + "&amount=" + amount_kobo;
using (var client = new HttpClient())
{
#if DNX451
// ignore server certificate error
//ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#elif DNXCORE50
// no implementation for the target DNX
#endif
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
client.DefaultRequestHeaders.Add("Hash",hash);
HttpResponseMessage response = await client.GetAsync(url);
string responsestr = "";
if (response.IsSuccessStatusCode)
{
responsestr = await response.Content.ReadAsStringAsync();
return Json(new { success = true, response = responsestr, hash = hash });
}
}
但是我的哈希没有被发送,当我在发送请求后检查浏览器时我没有看到我的哈希头,也应该将头部作为哈希类型发送,但我不知道该怎么做。
我尝试将此行更改为:
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("hash"));
仍然没有用。
更新 以下是浏览器中请求标头的屏幕截图 Request headers
似乎我的标题根本没有发送。