zoukankan      html  css  js  c++  java
  • HTTPClient学习

    https://www.cnblogs.com/liujisong2014221/articles/8269572.html

    转自这里

     1 //访问地址
     2         String uri = "";
     3         //创建client对象
     4         HttpClient client = HttpClients.createDefault();
     5         //创建post对象
     6         HttpPost post = new HttpPost(uri);
     7         
     8         //请求参数
     9         List<NameValuePair> paras = new ArrayList<NameValuePair>();
    10         //键值对
    11         paras.add(new BasicNameValuePair("username", "admin"));
    12         paras.add(new BasicNameValuePair("password", "123456"));
    13         
    14         //创建entity对象
    15         UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paras);
    16         
    17         //把entity对象放入post请求中
    18         post.setEntity(entity);
    19         //执行请求
    20         HttpResponse resp = client.execute(post);
    21         //获取服务端返回的数据
    22         HttpEntity en = resp.getEntity();
    23         //把en对象转为字符串
    24         String result = EntityUtils.toString(en);
    25         System.out.println("结果:"+result);

    拓展httpurlConnection

  • 相关阅读:
    Win7 安装
    线上java排查
    spring boot
    redisson
    Jcaptca 图片
    URL重写
    gradle导出依赖的jar包
    Redis tomcat
    flex 通过htmlservices链接moss的rest(rest 的get post方式)
    java语言MySQL批处理
  • 原文地址:https://www.cnblogs.com/chyxOne/p/9672683.html
Copyright © 2011-2022 走看看