我嘗試使用發送JSON從安卓到的NodeJS服務器
HttpURLConnection con = (HttpURLConnection) (new URL(IP + "/getrestaurant")).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "application/json");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write("{'restaurant_id':'569a16e28dcdc5c8add2a8e0'}".getBytes("UTF-8"));
con.getOutputStream().flush();
con.getOutputStream().close();
從Android設備發送請求到的NodeJS服務器當我打印從節點JS接收到的請求,我得到:
{
"{'restaurant_id':'569a16e28dcdc5c8add2a8e0'}": ""
}
而不是{'restaurant_id':'569a16e28dcdc5c8add2a8e0'}
我該如何得到它的工作?謝謝!
'{「restaurant_id」:「569a16e28dcdc5c8add2a8e0」}'是不是有效的JSON ... – Selvin