Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple values per key for application/x-www-form-urlencoded #195

Closed
wchill opened this issue Jul 19, 2017 · 1 comment
Closed
Assignees

Comments

@wchill
Copy link

wchill commented Jul 19, 2017

Similar to #15, but for function calls like FlurlClient.PostUrlEncodedAsync.

Basically I have a form that takes in multiple values for a single key; the resulting encoded form data is something like key[]=value1&key[]=value2&key[]=value3. This would work if I were doing a GET with query string, but as I need to POST the data I have to use a workaround like such:

var kvp = new List<KeyValuePair<string, string>>();
foreach (var v in values)
{
	kvp.Add(new KeyValuePair<string, string>("key[]", v.ToString()));
}

var webpage = await url
	.WithClient(_client)
	.PostAsync(new FormUrlEncodedContent(kvp))
	.ReceiveString();

This works just fine, but when I use HttpTest I'm not able to assert what the request body should be because it throws the following exception:

Flurl.Http.FlurlHttpException: RequestBody is only available when Request.Content derives from Flurl.Http.Content.CapturedStringContent

Ideally when POSTing a urlencoded form, we can take the same approach as in #15 and enumerate if a value is of IEnumerable type.

@tmenier
Copy link
Owner

tmenier commented Jul 26, 2017

I think this is a good enhancement, but unfortunately I'm clearing the deck for work on Flurl.Http 2.0. No dates set but this might sit for a while. In the mean time you can certainly use this in your own projects by registering a custom serializer. I will get this merged into the core eventually. Thanks!

@tmenier tmenier added this to the Flurl.Http 2.0 milestone Jul 26, 2017
@tmenier tmenier self-assigned this Jul 26, 2017
tmenier added a commit that referenced this issue Sep 3, 2017
@tmenier tmenier added the ready label Sep 3, 2017
@tmenier tmenier removed the ready label Oct 6, 2017
@tmenier tmenier closed this as completed Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants