본문 바로가기
프로그래밍/DB/JAVA/안드로이드/GAE

[안드로이드] HttpPost( POST 방식으로 파라메터 넘기기 )

by 아유카와 2011. 3. 18.
출처 : http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient

public void postData() {
   
// Create a new HttpClient and Post Header
   
HttpClient httpclient = new DefaultHttpClient();
   
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

   
try {
       
// Add your data
       
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs
.add(new BasicNameValuePair("id", "12345"));
        nameValuePairs
.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
        httppost
.setEntity(new UrlEncodedFormEntity(nameValuePairs));

       
// Execute HTTP Post Request
       
HttpResponse response = httpclient.execute(httppost);
       
   
} catch (ClientProtocolException e) {
       
// TODO Auto-generated catch block
   
} catch (IOException e) {
       
// TODO Auto-generated catch block
   
}
}