0

I need to make an HTTP request using HTTPClient. The web API requires that I add a custom header of this format:

HEADER: Authorization: consumer={consumerId}, consumerToken={consumerTokenValue}

Following is the Code:

string headr = "consumer=40816499,consumerToken=" + "test";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Clear();
            
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Authorization", headr);
var response =await client.PostAsJsonAsync<remitaData>(url, remd);
var chk = await response.Content.ReadAsStringAsync();

But I get this error message on execution:

The format of value 'consumer=40816499,consumerToken=test' is invalid.

Sh.Imran
  • 1,010
  • 7
  • 13

1 Answers1

0

You need to put a "type" at the start of the header. e.g.:

client.DefaultRequestHeaders.Add("Authorization", "custom " + headr);

(where the string "custom" is defined by the server).

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization (or

Moose Morals
  • 1,476
  • 26
  • 31
  • I do not understand can you please explain further because the link you gave was not helpful. Please note that my code runs perfectly on postman – Udeme Bassey Aug 16 '20 at 21:42