我们把上一篇没说的补上。
做接口呢首先要有http协议的基础。大家请自行学习。不过后续我也会介绍的。
那么下面是今天的内容。
那么我们今天来看一下post
public static void htpost() throws ClientProtocolException, IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httppost; HttpResponse response; HttpEntity entity; String postResult = null; String loginURL="http://192.168.8.241/index.php/Login/prologin"; httppost = new HttpPost(loginURL); //创建一个集合用来存储,post请求需要传入的参数。 List<NameValuePair> formparams1 = new ArrayList<NameValuePair>(); formparams1.add(new BasicNameValuePair("autologin", "1")); formparams1.add(new BasicNameValuePair("enter", "Sign in")); formparams1.add(new BasicNameValuePair("name", "admin")); formparams1.add(new BasicNameValuePair("password", "123456")); formparams1.add(new BasicNameValuePair("remember", "on")); httppost.setEntity(new UrlEncodedFormEntity(formparams1, "UTF-8")); response = httpClient.execute(httppost); entity = response.getEntity(); postResult = EntityUtils.toString(entity, "UTF-8"); System.out.println("查看登录接口请求返回的结果:" + postResult); httppost.releaseConnection(); }