使用ASP在POST请求的头中包含身份验证.净的核心



我正在尝试请求接收会话Id以与支付网关集成。

var m = System.Text.Encoding.Unicode.GetBytes("merchant." + merchant_Id + ":" + merchant_pass);
var b64Val = Convert.ToBase64String(m);
var SerSession = JsonConvert.SerializeObject(sessionRequest);
var client = new HttpClient();
string _ContentType = "application/json";
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_ContentType));
client.DefaultRequestHeaders.Add("Authorization", String.Format("Basic {0}", b64Val));
var _UserAgent = "d-fens HttpClient";
client.DefaultRequestHeaders.Add("User-Agent", _UserAgent);
HttpContent _Body = new StringContent(SerSession);
]_Body.Headers.ContentType = new MediaTypeHeaderValue(_ContentType);
HttpResponseMessage response;
response = await  client.PostAsync(api_URL, _Body);
var content = response.Content.ReadAsStringAsync().Result;
return Ok(content); 

我正在获得(无效凭据),我确信我使用的凭据是正确的。我已经在Python和PHP中测试过了。

try this

var authenticationString = $"{merchant_Id}:{merchant_pass}";
var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(authenticationString));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64EncodedAuthenticationString);

相关内容

  • 没有找到相关文章

最新更新