public class CallAPI extends AsyncTask<String, String, String> { public CallAPI(){//set context variables if required } @Override protected void onPreExecute() {super.onPreExecute(); } @Override protected String doInBackground(String... params) {String urlString = params[0]; // URL to callString data = params[1]; //data to postOutputStream out = null;try { URL url = new URL(urlString); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); out = new BufferedOutputStream(urlConnection.getOutputStream()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); writer.write(data); writer.flush(); writer.close(); out.close(); urlConnection.connect();} catch (Exception e) { System.out.println(e.getMessage());} } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)