I am trying to send a request to Identity verification company. They are asking to send three headers. I added the headers like so:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://api.test");
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
client.DefaultRequestHeaders.TryAddWithoutValidation("hmac-signature", Hmackey);
HttpRequestMessage request = new HttpRequestMessage();
request.Method = HttpMethod.Post;
request.Content = new StringContent(JSONFile, Encoding.UTF8,
"application/json");
HttpResponseMessage response = client.SendAsync(request).Result;
string responseContent = await response.Content.ReadAsStringAsync();
I posted the same JSON file in SOAP UI and I got the response back, but when I send the same JSON file using my code above, I get below error:
{
"responseHeader": {
"tenantID": "V2321",
"requestType": "PreciseIdOnly",
"clientReferenceId": "PIDInitial-2312313",
"expRequestId": "",
"messageTime": "2020-06-09T17:17:49Z",
"responseCode": "R0302",
"responseType": "ERROR",
"responseMessage": "The HMAC validation failed : Invalid Signature or no matching alias found."
},
"originalRequestData": null
}
The only difference is that in my code, I have "/r/n" and "/". I can remove "/r/n", but cannot remove "/" because double codes are preceded by forward slash.
Instead of calculating HMAC key, I got the HMAC key from SOAP UI from HTTP logs and put that in my code . I still get the same error saying "HMAC validation failed". I just want to make sure that does my code above looks right? I am supposed to add three headers like so:
Accept:application/json
Content-Type:application/json
hmac-signature:<TheCalculatedHMACSignature>
Does my code look right with these three headers. This is my first application where I am sending a request and I am thinking may be something in my code that is causing this error. I am not calculating HMAC key anymore. I am getting that key from SOAP UI Http logs and my response from SOAP UI looks good.
Any help in validating my code will be highly appreciated.