I'm using Flurl (one of my favorite APIs) to now post form-data to a url. I'm quite familiar using 'JsonProperty' attributes to name the keys, and use standard casing for c#.
But when I use PostUrlEncodedAsync, the normal JsonProperty code doesn't convert to 'key', but remains 'KeyName' and the call fails.
public class TokenTest
{
[JsonProperty("key")]
public string KeyName { get; set; }
}
So I'm a little baffled that this doesn't work right out of the box.
var request = new TokenTest
{
KeyName = "ewr1-QuQ5jo88WfCpNPz2kTb8ES",
};
var result = await url.PostUrlEncodedAsync(request).ReceiveString();
My call fails since it wants 'key', but I'm sending 'KeyName'. JsonProperty/DataMember attributes have always worked in the past, so why is it failing here?
As I work on the problem, it seems to stem from the fact that this method calls DefaultUrlEncodedSerializer
to do the serialization. This serializer ignores the JsonProperty names.
var urlEncodedContent = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(token));
var jsonEncodedContent = new CapturedUrlEncodedContent(request.Settings.JsonSerializer.Serialize(token));
For example, the jsonEncodedContent uses the JsonProperty
attribute, while the urlEncodedContent ignores the attribute.