Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created January 25, 2011 09:57
Show Gist options
  • Save rummelonp/794731 to your computer and use it in GitHub Desktop.
Save rummelonp/794731 to your computer and use it in GitHub Desktop.
org.apache.httpとjava.net比較
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();
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