Handling white spaces in query params

I want to pass q query param 'city' with value as 'Andhra Pradesh'. When I query with the url having the query param value with white space, it is giving me bad request error.

And I replace the white space with %20, no luck!!! and with single quotes and double quotes also not working... How to handle with spaces in apigee with out any errors.Can any one help me

Solved Solved
0 8 49.4K
2 ACCEPTED SOLUTIONS

Not applicable

RFC 3986 specifically omits spaces as valid elements of a URI. Typically user-agents will encode your URI for you when they encounter a space with either "%20" or in some cases "+". Can you share which user agent (CURL, browser, Postman, CFNetwork, etc) you are using?

I have observed this behavior before and it is entirely due to the lack of encoding. Some libraries take care of this for you, some require you to explicitly encode the URL.

View solution in original post

@Dallen Yes, I agree to your answer. In current Scenario, I am testing the url in apigee only. So, due to the space in query param value, it is unable to reach to the proper method.

I have manually encoded the white space in the url, but still no luck.

So I have approached a java script policy to encode my url and then use another policy to decode in the response section. That works for me. Thanks a lot to all to post your responses.

View solution in original post

8 REPLIES 8

@Mukkala Radhika , Welcome to Apigee community !

What do you mean "When I query with the url having the query param value with white space, it is giving me bad request error." ?

Can you please explain ?

Yes, When I use the request url like 'http://host:port/basepath?city=Andhra Pradesh', The request is not hitting the proper GET method. And I am getting 400 error.

In similar way when I query with the url like 'http://host:port/basepath?city=Chennai', I got proper response which is expected with 200 status code.

@Mukkala Radhika
curl 'http://host:port/basepath?city=Andhra Pradesh'
curl http://host:port/basepath?city='Andhra Pradesh'
or curl http://host:port/basepath?city=Andhra%20Pradesh should work.

If you are using curl to test, run with -v to see what is going in your GET to Edge and also trace the calls and see what is being received on Edge.

Are you sure that error is originating from Apigee? Apigee does not do any query string validation as such by default. Is it possible that the error is coming from your target servers? The way to find out is to trace the request to see which point the error is raised.

Not applicable

RFC 3986 specifically omits spaces as valid elements of a URI. Typically user-agents will encode your URI for you when they encounter a space with either "%20" or in some cases "+". Can you share which user agent (CURL, browser, Postman, CFNetwork, etc) you are using?

I have observed this behavior before and it is entirely due to the lack of encoding. Some libraries take care of this for you, some require you to explicitly encode the URL.

@Dallen Yes, I agree to your answer. In current Scenario, I am testing the url in apigee only. So, due to the space in query param value, it is unable to reach to the proper method.

I have manually encoded the white space in the url, but still no luck.

So I have approached a java script policy to encode my url and then use another policy to decode in the response section. That works for me. Thanks a lot to all to post your responses.

Hi, I am stuck with the same issue, my problem statement is same and I am getting 401 unauthorized error(I am using HMAC encryption).

How did you solve?