7

Does anyone know how to send a field with brackets by a url encoded form using flurl?

Example: I want to send the foo[bar] field with the "foo" value like this

var response = await "https://server/request"
    .WithHeader("Header1", "headerValue")
    .PostUrlEncodedAsync(new
    {
         foo[bar] = "foo"
    })
1
  • That is not accepted by c# Commented Feb 10, 2017 at 18:30

1 Answer 1

7

Brackets aren't allowed in C# identifiers, so using an anonymous object to represent a name/value pair won't work here. However, in all cases where Flurl parses an object to name/value pairs, it gives special treatment to dictionaries. So you can do this:

var response = await "https://server/request"
    .WithHeader("Header1", "headerValue")
    .PostUrlEncodedAsync(new Dictionary<string, string>()
    {
        { "foo[bar]", "foo" }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.