개발/개발 자료

[Android] Http 통신하는 예제 (POST통신)

시원한물냉 2013. 12. 7. 19:42

try {

HttpClient client = new DefaultHttpClient();

String postURL = id.url + "/android_memo_insert.jsp";

HttpPost post = new HttpPost(postURL);

List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("name", id.id));

params.add(new BasicNameValuePair("title", title.getText().toString()));

params.add(new BasicNameValuePair("content", content.getText().toString()));


  UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);

post.setEntity(ent);

HttpResponse responsePOST = client.execute(post);

HttpEntity resEntity = responsePOST.getEntity();

if (resEntity != null) {

Log.i("RESPONSE", EntityUtils.toString(resEntity));

}

} catch (Exception e) {

e.printStackTrace();

}