Created
January 25, 2011 09:57
-
-
Save rummelonp/794731 to your computer and use it in GitHub Desktop.
org.apache.httpとjava.net比較
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
DefaultHttpClient client = new DefaultHttpClient(); | |
HttpPost post = new HttpPost(url); | |
MultipartEntity entity = new MultipartEntity(); | |
entity.addPart("email", new StringBody(email)); | |
entity.addPart("password", new StringBody(password)); | |
post.setEntity(entity); | |
HttpResponse responce = client.execute(post); | |
int statusCode = responce.getStatusLine().getStatusCode(); | |
InputStream content = responce.getEntity().getContent(); |
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
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); | |
con.setDoInput(true); | |
con.setDoOutput(true); | |
con.setRequestMethod("POST"); | |
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream()); | |
writer.write("email=" + URLEncoder.encode(email) +"&password=" + URLEncoder.encode(password)); | |
writer.flush(); | |
con.connect(); | |
int statusCode = con.getResponseCode(); | |
InputStream content = con.getInputStream(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment