question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matching one form-urlencoded value

See original GitHub issue

If I have a IRequestBuilder, what do I do to make it only match when a single, specific form key/value is set?

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
StefHcommented, Mar 17, 2023

I’ve added this unit test:

[Fact]
    public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithFunc()
    {
        // Arrange
        var server = WireMockServer.Start();
        server.Given(
            Request.Create()
                .UsingPost()
                .WithPath("/foo")
                .WithBody(values => values != null && values["key1"] == "value1")
            )
            .RespondWith(
                Response.Create()
            );

        // Act
        var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("key1", "value1") });
        var response = await new HttpClient()
            .PostAsync($"{server.Url}/foo", content)
            .ConfigureAwait(false);

        // Assert
        response.StatusCode.Should().Be(HttpStatusCode.OK);

        server.Stop();
    }

Which scenario you also will use I think.

A new normal NuGet version will be released later today / tomorrow.

1reaction
StefHcommented, Mar 15, 2023

@terryaney

You should now be able to use WithBody(Func<IDictionary<string, string>?, bool> func);

Use NuGet preview version : 1.5.18-ci-17167

Info --> https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Match urlencoded data from file
Is there a way to match a HTTP POST urlencoded data (Content-Type: application/x-www-form-urlencoded) in a file? The matched strings will ...
Read more >
Body params when form-urlencoded are not seeming to ...
Using a nil, boolean, or fixnum value in my expected body hash, on a form-urlencoded request, the request will never match.
Read more >
How do you build a application/x-www-form-urlencoded ...
I need to post a form encoded body that essentially looks like ... Your example doesn't include any values that would need to...
Read more >
[Consume API] Object format for x-www-form-urlencoded
Hi,. I'm consuming a REST API that only accepts x-www-form-urlencoded. I'm trying to request an object: id={ "number":"500",. "month":"12",. "year":"20",.
Read more >
Send Array as Part of x-www-form-urlencoded Using ...
In this tutorial, we'll explore the ways to send an array as part of the x-www-form-urlencoded using Postman.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found