Simple post request for java interface automation

Let's add what we didn't say in the previous post.

To make an interface, we must first have the basis of the http protocol. Please learn by yourself. But I will introduce it later.

So here is today's content.

So let's take a look at the post today

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);
                  //Create a collection to store the parameters that the post request needs to pass in.
		 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("View the result returned by the login interface request: " + postResult);
         httppost.releaseConnection();  
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326021889&siteId=291194637