Search code examples
androidandroid-annotations

Android Annotations: Query params gets appended to url?


@Get("/ServiceTest?version=1&dateRange={dateRange}")
ResponseModel getDateRangeTest(String dateRange);

in RestClient interface this make the following Get

http://localhost:8080/ServiceTest/2014-01-29%25202014-01-29?version=1" resulted in 400 (Bad Request); invoking error handler

Am i doing something wrong in sending the query params.

I want address this way:

/ServiceTest?version=1&dataRange=2014-01-29%25202014-01-29

Which in this case somehow i am failed to generate with Android annotations @Get

Answer: My calls were not correct and main problem was with uri encode, correct one is

/ServiceTest?version=1&dataRange=2014-01-29%202014-01-29

Solution

  • you might do wrong.

    Your server get /ServiceTest
    but you access server with address /ServiceTest/2014-01-29%25202014-01-29

    Look careful that your server receive as /ServiceTest?version=1&dateRange={dateRange} and {dataRange} is what you intend to give as variable.

    Your address should be /ServiceTest?version=1&dataRange=2014-01-29%25202014-01-29

    == EDIT ==

    I'm not familiar with Android Get annotation, but try this.

    @Get("/ServiceTest?version=1&dateStart={dateStart}&dateEnd={dateEnd}")
    ResponseModel getDateRangeTest(String dateStart, String dateEnd);
    

    and access with /ServiceTest?version=1&dataStart=2014-01-29&dateEnd=2014-01-29

    Note that I change argument for more specific. and it would be a better approach.