How to make REST API calls that have filter added

I am new to REST API and I want to make a REST API call which returns a JSON object

http://smlookup.dev/sec/products?search={"ABC.CP":"123A5"} - Runs fine in a browser and gives a JSON object

how do i get '?search={"ABC.CP":"12345"}' this expression to work as it filter the records

Code i am using is

    String serverUrl="http://smlookup.dev/sec/products?search=";
    String search=URLEncoder.encode("={"ABC.CP":"12345"}");
    URL url = new URL(serverUrl+search);
        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
        httpCon.setDoOutput(true);
        httpCon.setRequestMethod("GET");
        OutputStream out = httpCon.getOutputStream();

            //FAILS GIVING 405 STATUS CODE                       
        int responseCode = httpCon.getResponseCode();

All help or suggestions are helpful

Thanks!


Not sure if its normal but you dont send any data in your POST. Furthermore you should urlencode your url, the inverted comma are not accepted like that.

URLEncoder.encode("={"Xref.CP":"XAW3123A5"}");
链接地址: http://www.djcxy.com/p/45660.html

上一篇: 使用JSON缓存响应

下一篇: 如何创建添加了过滤器的REST API调用