如何进行添加了过滤器的 REST API 调用
How to make REST API calls that have filter added
我是 REST 的新手 API,我想进行一个 REST API 调用,其中 returns 一个 JSON 对象
http://smlookup.dev/sec/products?search={"ABC.CP":"123A5"} - 在浏览器中运行良好并给出一个 JSON 对象
如何让 '?search={"ABC.CP":"12345"}' 这个表达式在过滤记录时起作用
我使用的代码是
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();
所有帮助或建议都有帮助
谢谢!
不确定是否正常,但您没有在 POST 中发送任何数据。
此外,您应该 url 对您的 url 进行编码,这样不接受倒逗号。
URLEncoder.encode("={\"Xref.CP\":\"XAW3123A5\"}");
我是 REST 的新手 API,我想进行一个 REST API 调用,其中 returns 一个 JSON 对象
http://smlookup.dev/sec/products?search={"ABC.CP":"123A5"} - 在浏览器中运行良好并给出一个 JSON 对象
如何让 '?search={"ABC.CP":"12345"}' 这个表达式在过滤记录时起作用
我使用的代码是
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();
所有帮助或建议都有帮助
谢谢!
不确定是否正常,但您没有在 POST 中发送任何数据。 此外,您应该 url 对您的 url 进行编码,这样不接受倒逗号。
URLEncoder.encode("={\"Xref.CP\":\"XAW3123A5\"}");