Android HTTPpost 提交数据到服务器

public void send() {
    HttpPost request = new HttpPost(" http://192.168.1.8:8080/AndroidWeb/InsertServlet");
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    BasicNameValuePair im = new BasicNameValuePair("imageid", imageid+"");
    BasicNameValuePair  un = new BasicNameValuePair("uname",name.getText()+"") ;
    BasicNameValuePair  pw = new BasicNameValuePair("password", password.getText()+"");
    String sex ;
    if(sex_man.isChecked()){
     sex = "M";
    }else{
     sex = "W";
    }
    BasicNameValuePair sx = new BasicNameValuePair("sex", sex);
    BasicNameValuePair br = new BasicNameValuePair("birthday", birthday.getText()+"");
    
    parameters.add(un);
    parameters.add(im);
    parameters.add(pw);
    parameters.add(sx);
    parameters.add(br);
    
    HttpEntity en;
    try {
     en = new UrlEncodedFormEntity(parameters,HTTP.UTF_8);
     request.setEntity(en);
    } catch (UnsupportedEncodingException e1) {
     e1.printStackTrace();
    }
    DefaultHttpClient dhc = new DefaultHttpClient();
    try {
     HttpResponse response = dhc.execute(request);
    } catch (Exception e) {
     e.printStackTrace();
    }
     }
  }

你可能感兴趣的:(Android HTTPpost 提交数据到服务器)