[英]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.