Stream: dotnet
Topic: adding headers
Mat Coolidge (Jul 14 2017 at 18:15):
how do you add headers to the fhir client?
Theo Stolker (Jul 17 2017 at 07:07):
Hi @Mat Coolidge , you can add an OnBeforeRequest handler to the FHIRClient, like in the following sample:
private static void AddHeaders(object ClientObject, BeforeRequestEventArgs BREA)
{
BREA.RawRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")));
BREA.RawRequest.Headers.Add("X-Your-header", "xyz");
}
static void Main(string[] args)
{
FhirClient client = new FhirClient(FHIRBase);
client.OnBeforeRequest += AddHeaders;
// Your code
}
Yunwei Wang (Jul 20 2017 at 14:39):
Here is my solution:
Yunwei Wang (Jul 20 2017 at 14:39):
var client = new FhirClient(serviceUrl)
{
PreferredFormat = ResourceFormat.Json
};
client.OnBeforeRequest +=
(sender, e) => { e.RawRequest.Headers.Add("Authorization", token); };
Brian Postlethwaite (Jul 24 2017 at 03:52):
Yup, that's right.
Last updated: Apr 12 2022 at 19:14 UTC