Last active
January 28, 2017 13:50
-
-
Save mizucoffee/c273ba097f7586a58c2164549a47f743 to your computer and use it in GitHub Desktop.
サンプル
This file contains hidden or 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
try { | |
URL url = new URL("http://www.example.com/"); | |
URLConnection uc = url.openConnection(); | |
uc.setDoOutput(true); | |
uc.setRequestProperty("Content-type", "application/json"); | |
OutputStream os = uc.getOutputStream(); | |
PrintStream ps = new PrintStream(os); | |
ps.print("post message"); | |
ps.close(); | |
InputStream is = uc.getInputStream(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); | |
StringBuffer sb = new StringBuffer(); | |
String s; | |
while ((s = reader.readLine()) != null) { | |
sb.append(s); | |
} | |
if (resLis != null) | |
resLis.onResponse(sb.toString()); | |
reader.close(); | |
} catch (IOException e) { | |
if (errLis != null) | |
errLis.onError(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment