本文共 1262 字,大约阅读时间需要 4 分钟。
??????? HTTP ??????????????????
URL url = new URL(path);HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod(method);httpURLConnection.setRequestProperty("accept", "*/*");httpURLConnection.setRequestProperty("connection", "Keep-Alive");httpURLConnection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); OutputStreamWriter out = new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8");out.write(data);out.flush();InputStream inputStream = httpURLConnection.getInputStream();br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));String str = "";while ((str = br.readLine()) != null) { result.append(str);}return result.toString(); ????? new URL(path) ?? URL ?????????? HttpURLConnection ??????????????????? HTTP ?????????????
???????????????????????????? method?????????????????????????????????????????????
???setDoOutput(true) ? setDoInput(true) ????????????????????????????????
?? OutputStreamWriter ???? UTF-8 ????????????????????????? InputStreamReader ?????????????????????????????
?????????? JSON ????????????????????????????????
转载地址:http://eipc.baihongyu.com/