2

I need to send a JSON file to the credit card company. They are asking for three headers. I tried to include the header like so:

var client = new HttpClient();


                var httpRequestMessage = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri("https://test"),
                    Headers = {

                            { HttpRequestHeader.Authorization.ToString(), Hmackey },
                            { HttpRequestHeader.Accept.ToString(), "application/json" },
                            { HttpRequestHeader.ContentType.ToString(), "application/json" },

                        },
                    // Content = new StringContent(JsonConvert.SerializeObject(postParameters))
                    Content = new StringContent(JSONFormat)
                };

per the credit card company, The headers are below:

Accept:application/json
Content-Type:application/json
hmac-signature:[TheCalculatedHMACSignature]

when I put the calculated HMAC key signature, I get this error:

The format of value 'ftretretret354325ttt6Md3Ds/S12cfI=' is invalid.

I am thinking it is because of "=" and "/" sign in the HMAC signature, but I do not know how to resolve this. I also looked at the following post:

https://stackoverflow.com/questions/13198090/adding-httpclient-headers-generates-a-formatexception-with-some-values

I am not sure how to add below code in my existing code.

http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "key=XXX");
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
rimi
  • 624
  • 5
  • 15
  • Please show us the header how it should look like as from the docs and show us the header you are currently sending (both as text) – Sir Rufo Jun 07 '20 at 06:39

0 Answers0