当前位置:操作系统 > 安卓/Android >>

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 易做图 ;
    if(易做图_man.isChecked()){
     易做图 = "M";
    }else{
     易做图 = "W"; 
    }
    BasicNameValuePair sx = new BasicNameValuePair("易做图", 易做图);
    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 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,