[英]How to make REST API calls that have filter added
我是REST API的新手,我想进行一个REST API调用,该调用返回一个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中发送任何数据。 此外,你应该urlencode你的网址,倒置的逗号不被接受。
URLEncoder.encode("={\"Xref.CP\":\"XAW3123A5\"}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.