How to encode query parameters on a url in Specflow? the GET Call for API with Search options with changing scenarios as Case with searchOperator used = equal, in, like
GET API call for
url.com/?SearchOptions=[{"Searchby":"title","searchOperator":"contains","searchValue1":"testing"}]
stepdefination
[When(@"Requesting for Search: (.*), (.*)")]
public void WhenAGetRequestSearchOnly(string searchOption, int statusCode)
{
switch (statusCode)
{
case 401:
Token=invalidtoken"; - This pass
case 200:
Token="invalidtoken"; -Failed 400 (def url is not encoded properly)
break;
}
SetResponse(EndPoints.GetResponseSearchOnly(_Token, searchOption, statusCode));
}
- Same is coming in postman (which means url is not properly encoded)
Need url to hit - /endpointapi?SearchOptions=[{%22Searchby%22:%22title%22,%22searchOperator%22:%22contains%22,%22filterValue1%22:%22testing%22}]
API GET call works fine url.com/?SearchOptions=[{"Searchby":"title","searchOperator":"contains","searchValue1":"testing",searchValue2":""}]
When endoded this url it comes like this
%7B%22SearchBy%22%3A%22title%22%2C%22SearchOperator%22%3A%22contains%22%2C%20%22SearchValue1%22%3A%22Testing%22%7D
which is giving above error
As an Example browser url is seen working fine (pls ignore the values of json)
Note- used online json query encoder filter
This has been resolved by using below reference
References:
Prints: