Created
February 23, 2016 05:12
-
-
Save miaodonghan/b88b6505c7dd1fbadfe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected String doInBackground(String... data) { | |
HttpURLConnection urlConnection = null; | |
try { | |
URL url = new URL("http://192.168.1.7:1337/api/doc"); | |
urlConnection = (HttpURLConnection) url.openConnection(); | |
urlConnection.setRequestMethod("POST"); | |
urlConnection.setRequestProperty("Accept", "application/json"); | |
urlConnection.setRequestProperty("Content-type", "application/json"); | |
urlConnection.setRequestProperty("charset", "utf-8"); | |
JSONObject jsonParam = new JSONObject(); | |
jsonParam.put("name", "25"); | |
jsonParam.put("content", "Real"); | |
String requestData = jsonParam.toString(); | |
urlConnection.setRequestProperty("Content-Length", "" + requestData.getBytes().length); | |
DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream()); | |
out.writeBytes(requestData); | |
out.flush (); | |
out.close (); | |
InputStream in = new BufferedInputStream(urlConnection.getInputStream()); | |
Scanner s = new Scanner(in).useDelimiter("\\A"); | |
String res = s.hasNext() ? s.next() : ""; | |
return res; | |
} catch (Exception ex) { | |
Log.e("er55r",ex.getMessage()); | |
} finally { | |
urlConnection.disconnect(); | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment