欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Android通过HttpClient执行post请求,androidhttpclient,public void

来源: javaer 分享于  点击 4065 次 点评:102

Android通过HttpClient执行post请求,androidhttpclient,public void


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    }} 
相关栏目:

用户点评