I want to add custom HTTP Header(hashed and signed) encoded in utf8 encoding (Encoding.UTF8.GetString). When the data is POSTed to IIS, Bad Request(400) error is encountered.
If the custom HTTP Header is encoded in base64 encoding, and there's no problem. But our partner is insisting to use utf8 encoding.
I want to know whether this "Bad Request(400)" is only caused by IIS?
And here is the code:
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post,
"https://putsreq.com/AIWKVacHh2ok5FMGFpEg");
var reqBody = "{'hello': 'world'}";
msg.Content = new StringContent(reqBody);
msg.Content.Headers.ContentType = new
MediaTypeWithQualityHeaderValue("application/json");
var signature = SignMessage(reqBody); //hash and sign the message using
//private key
var signatureString = Encoding.UTF8.GetString(signature);
msg.Headers.Add("signature", signature);
try{
var response = await client.SendAsync(msg);
response.EnsureSuccessStatusCode();
//Continue if success
}catch(Exception ex){
Trace.WriteLine("Exception: " + ex);
}