zoukankan      html  css  js  c++  java
  • Post And Get接口测试

    public class TestPost {
     
    public static String do_post(String url, Map<String, String> params) throws IOException {
      String body = "{}";
      DefaultHttpClient httpclient = new DefaultHttpClient();
      try {
      HttpPost httpost = new HttpPost(url);
      //添加参数
      params.put("", "");
      params.put("", "");
      params.put("", "");
      params.put("", "");
      params.put("", "");
      params.put("", "");
      //设置格式
      //JSONObject jo = JSONObject.fromObject(params);
      JSONObject jo = new JSONObject(params);
      StringEntity entity = new StringEntity(jo.toString(), "UTF-8");
      httpost.setEntity(entity);
     
      HttpResponse response = httpclient.execute(httpost);
      HttpEntity rEntity = response.getEntity();
      body = EntityUtils.toString(rEntity);
      System.out.println(body);
      } finally {
      httpclient.getConnectionManager().shutdown();
      }
      return body;
      }
     
      public static String do_get(String url) throws ClientProtocolException, IOException {
      String body = "{}";
      DefaultHttpClient httpclient = new DefaultHttpClient();
      try {
      HttpGet httpget = new HttpGet(url);
      HttpResponse response = httpclient.execute(httpget);
      HttpEntity entity = response.getEntity();
      body = EntityUtils.toString(entity);
      } finally {
      httpclient.getConnectionManager().shutdown();
      }
      return body;
      }
     
     
    public static void main(String[] args) {
     
    String url = "*******************************************************";
    Map<String, String> params = new HashMap<String, String>();
    try {
    do_post(url, params);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
  • 相关阅读:
    Cayley's Tree Formula & Prufer's Method
    POJ 2262:Goldbach's Conjecture
    The Sieve of Eratosthenes (素数筛选法)
    POJ 2244:Eeny Meeny Moo(稍加变形的约瑟夫问题)
    POJ 1595:Prime Cuts
    iframe标签的使用
    js笔记
    Asp.Net知识点
    Reapte控件的使用
    浮躁十年
  • 原文地址:https://www.cnblogs.com/fqfanqi/p/6081514.html
Copyright © 2011-2022 走看看