I'm using an API that's in beta and it's essentially a querystring for a Mongodb db as a parameter. Refit is encoding my url, which included plenty of curly braces, and their server doesn't like it and it essentially ignores all of my query attributes.
I've tried passing the entire query as a string, which doesn't work but also doesn't chuck an error. I've found a commit to Refit which directly addresses this issue here.
That says to use the header [QueryUriFormat(UriFormat.Unescaped)]
, which sounds great, but I'm clearly not using the library the QueryUriFormat
attribute is in and I can't find it in a google search.
In the interface:
[QueryUriFormat(UriFormat.Unescaped)]
[Headers("Authorization: Basic")]
[Get("/stuff/etc")]
Task<myModel> GetStuff(string q);
The string:
"filter={name:'THENAME',timestamp:{$gt:1571238110000},TOTAL_MB: {$gt:0},thingyId:{$eq:2500}}";
The call:
var result = client.GetUsageSince(stringB).Result;
I tried the link on the first comment (below)
var HttpClient = new HttpClient(new UriQueryUnescapingHandler()) { BaseAddress = new Uri(url) };
HttpClient.DefaultRequestHeaders.Add("Accept", "application/json");
HttpClient.DefaultRequestHeaders.Add("Content", "application/json");
var byteArray = Encoding.UTF8.GetBytes($"{username}:{password}");
HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
Stuff = RestService.For<IStuff>(HttpClient, refitSettings);
After doing this it looks like the absolute Uri is now correct, but the basic auth header is not working on my customer HttpClient
.