0

I am trying to encode a URL with special character and OR operator. This is how the URL looks like:

https://example.net/house/info?_queryFilter=_id+eq+%27333a22e7-5g5g-4sd5-df67-fg66a9da8027%27+or+_id+eq+%2756nm67d0-7687-4d70-fg45-22d6745423a7%27

NOTE: 333a22e7-5g5g-4sd5-df67-fg66a9da8027 and 56nm67d0-7687-4d70-fg45-22d6745423a7 in above URL indicates houseID

This is the code I am using for looping through the houseID:

for (int i = 0; i < apiResponse.getHouses().size(); i++) {
        if (houseQuery == null) {
            houseQuery = "_id+eq+".concat("'").concat(apiResponse.getHouses().get(i).getHouseId()).concat("'");
        } else {
            houseQuery = houseQuery.concat("+or+_id+eq+").concat("'").concat(apiResponse.getHouses().get(i).getHouseId()).concat("'");
        }
    } 

This is my API interface:

@GET(UrlConstants.URL_GET_HOUSE)
void getHouseInfo(
        @Header(Constants.HEADER_SESSIONID) String sessionID,
        @Query(Constants.QUERY_FILTER) String query,
        Callback<HouseInfoResponse> houseInfoResponseCallback);

I am getting the following error in the logs:

{"code":400,"reason":"Bad Request","message":"The value '_id+eq+'333a22e7-5g5g-4sd5-df67-fg66a9da8027'+or+_id+eq+'56nm67d0-7687-4d70-fg45-22d6745423a7'' for parameter '_queryFilter' could not be parsed as a valid query filter"}

I will appreciate any help.

  • Does this answer your question? [URL encoding in Android](https://stackoverflow.com/questions/3286067/url-encoding-in-android) – JosefZ Mar 21 '21 at 10:53

2 Answers2

0

Try to encode your URL to see if it works , for example use %27 instead of ' .

You can use this web site to encode

0

The issue was that the sign + in _id+eq+ was getting replaced with two-digit hexadecimal representation, starting with %), i.e. %2B. The server wasn't expecting the encoding of + in query prefix _id+eq+ and +or+_id+eq+.

Solution: Specifying the encodeValue as False while specifying Query attribute worked.

@Header(Constants.HEADER_SESSIONID) String sessionID,
@Query(value = Constants.QUERY_FILTER, , encodeValue = false) String query,
    Callback<HouseInfoResponse> houseInfoResponseCallback);