zoukankan      html  css  js  c++  java
  • post请求提交表单数据

    //1.创建client对象
     HttpClient client = new DefaultHttpClient();
    //2.创建get请求对象
     HttpGet get = new HttpGet(path);
    //3.使用client发送get请求
     HttpResponse response = client.execute(get);
     //获取状态行
     StatusLine line = response.getStatusLine();
     //4.获取状态码
     int code = line.getStatusCode();  
     //5.获取实体
     HttpEntity entity = response.getEntity();  
       
    小部分代码:
    HttpClient client = new DefaultHttpClient();
                    //2.创建get请求对象
                    HttpGet get = new HttpGet(path);
                    try {
                        //3.使用client发送get请求
                        HttpResponse response = client.execute(get);
                        //获取状态行
                        StatusLine line = response.getStatusLine();
                        //获取状态码
                        int code = line.getStatusCode();
                        if(code == 200){
                            //获取实体
                            HttpEntity entity = response.getEntity();
                            InputStream is = entity.getContent();
                            String text = Tools.getTextFromStream(is);
                            
                            Message msg = handler.obtainMessage();
                            msg.obj = text;
                            handler.sendMessage(msg);
                        }
                        
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                        
  • 相关阅读:
    Linux 命令
    Linux 命令
    Linux 命令
    Linux 命令
    121.Best Time to Buy and Sell Stock---dp
    136.Single Number---异或、位运算
    141.Linked List Cycle---双指针
    Restful接口设计
    socket网络编程
    107.Binary Tree Level Order Traversal II
  • 原文地址:https://www.cnblogs.com/SoulCode/p/6393418.html
Copyright © 2011-2022 走看看