zoukankan      html  css  js  c++  java
  • HttpClient请求网络数据的Post请求

    new Thread(){
                public void run() {
                    
                    try {

                       //获得输入框内容
                        String phonenum=et_phone_num.getText().toString().trim();
                        String password=et_password.getText().toString().trim();
                        String name=et_name.getText().toString().trim();
                        
                        
                        HttpClient client=new DefaultHttpClient();
                        HttpPost post=new HttpPost(urlPath);
                        //将汉字编码
                        String ss=URLEncoder.encode(name, "utf-8");
                        
                        List<NameValuePair> parameters=new ArrayList<NameValuePair>();
                        parameters.add(new BasicNameValuePair("userName", ss));
                        parameters.add(new BasicNameValuePair("userPhone", phonenum));
                        parameters.add(new BasicNameValuePair("userPassword", password));
                        
                        HttpEntity entity=new UrlEncodedFormEntity(parameters,"utf-8");
                        post.setEntity(entity);
                        HttpResponse response=client.execute(post);
                        StatusLine line=response.getStatusLine();
                        int code=line.getStatusCode();
                        if (code==200) {
                            HttpEntity entity2=response.getEntity();
                            String result=EntityUtils.toString(entity2,"utf-8");
                            Message message=new Message();
                            message.obj=result;
                            message.what=1;
                            handler.sendMessage(message);
                        }
                        
                        
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                };
            }.start();

  • 相关阅读:
    时间序列数据库(TSDB)初识与选择(InfluxDB、OpenTSDB、Druid、Elasticsearch对比)
    Prometheus COMPARISON TO ALTERNATIVES
    认真分析mmap:是什么 为什么 怎么用
    Flume学习之路 (二)Flume的Source类型
    Flume学习之路 (一)Flume的基础介绍
    Spark学习之路 (二十一)SparkSQL的开窗函数和DataSet
    Spark学习之路 (二十)SparkSQL的元数据
    CentOS 7的安装
    Spark学习之路 (十九)SparkSQL的自定义函数UDF
    Spark学习之路 (十八)SparkSQL简单使用
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/5779941.html
Copyright © 2011-2022 走看看