url param - how to accept either of multiple values #189

Closed
opened 2025-12-29 14:24:40 +01:00 by adam · 2 comments
Owner

Originally created by @gregoks on GitHub (Jul 11, 2019).

Hi,

I'm trying to create mapping to accept both of the following GET requests:

http://localhost:5566/test?abc=123
http://localhost:5566/test?abc=456

I have tried several options but none of them accept them both:

  1. Set 2 mappings for both of the values:
requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "123");
requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "456");
  1. Set 1 mapping with the values as array:

requestMatcher.WithParam("abc" , "123", "456" );

this option will only accept requests that look like this - http://localhost:5566/test?abc=123&abc=456


Setting mapping for one of the values will work but only for that one value, so this single mapping:

requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "123");

will be able to accept request http://localhost:5566/test?abc=123

Can you please assist?

Thanks,

Greg

Originally created by @gregoks on GitHub (Jul 11, 2019). Hi, I'm trying to create mapping to accept both of the following GET requests: http://localhost:5566/test?abc=123 http://localhost:5566/test?abc=456 I have tried several options but none of them accept them both: 1. Set 2 mappings for both of the values: ``` requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "123"); requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "456"); ``` 2. Set 1 mapping with the values as array: `requestMatcher.WithParam("abc" , "123", "456" );` this option will only accept requests that look like this - http://localhost:5566/test?abc=123&abc=456 ----------- Setting mapping for one of the values will work but only for that one value, so this single mapping: `requestMatcher.WithParam("abc", MatchBehaviour.AcceptOnMatch, true, "123");` will be able to accept request http://localhost:5566/test?abc=123 Can you please assist? Thanks, Greg
adam added the question label 2025-12-29 14:24:40 +01:00
adam closed this issue 2025-12-29 14:24:40 +01:00
Author
Owner

@StefH commented on GitHub (Jul 11, 2019):

Good question.

The best option would be to use a RegexMatcher (https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#regular-expression-matching).

This is supported !
Just use:

.WithParam("key", MatchBehaviour.AcceptOnMatch, new RegexMatcher("[123|456]"))
@StefH commented on GitHub (Jul 11, 2019): Good question. The best option would be to use a RegexMatcher (https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#regular-expression-matching). **This is supported !** Just use: ``` c# .WithParam("key", MatchBehaviour.AcceptOnMatch, new RegexMatcher("[123|456]")) ```
Author
Owner

@gregoks commented on GitHub (Jul 12, 2019):

Thanks I will try!

@gregoks commented on GitHub (Jul 12, 2019): Thanks I will try!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#189