2014년 8월 7일 목요일

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

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();
}

댓글 없음:

댓글 쓰기