• 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();
                    }
                        
  • 相关阅读:
    二分查找,你真的学会了吗
    解决Devexpress的RichEditControl控件保存为docx文件后在word里打开字体显示不正确的问题
    protocgengo: unable to determine Go import path for "xxx.proto"
    URL 和 URI 区别
    Ubuntu 强制关闭图形窗口
    centos /lib64/libc.so.6: version `GLIBC_2.28' not found (required by
    Mac OS 修改终端 Terminal 的配色
    Go语言 http 中的 request.Host 和 request.URL.Host 的区别
    Go 中 defer 和 return 执行的先后顺序
    NPOI 将DataSet保存成Excel文件
  • 原文地址:https://www.cnblogs.com/SoulCode/p/6393418.html
Copyright © 2020-2023  润新知