package com.js.ai.modules.pointwall.interfac; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.activiti.engine.impl.util.json.JSONObject; import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; /** * * @ClassName: TestLogin * @Description: TODO 客戶端模拟登录 * @author: * @date: */ public class TestLogin { public String login(String userName,String password){ CloseableHttpClient httpclient = HttpClients.createDefault(); String url = "http://27.155.64.173:8687/pointwall/a/client/login"; HttpPost httpPost = new HttpPost(url); //建立HttpPost对象 List<NameValuePair> params=new ArrayList<NameValuePair>(); JSONObject jsonObject = new JSONObject(); jsonObject.put("loginName", userName);//用户名 jsonObject.put("password", password);//密码 //建立一个NameValuePair数组,用于存储欲传送的参数 params.add(new BasicNameValuePair("userInfo",jsonObject.toString())); try { httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8)); CloseableHttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); //打印目标网站输出内容 String responseHtmQueryPage = IOUtils.toString(entity.getContent());// 获取相应的网页内容 System.out.println(responseHtmQueryPage+"====="); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } public static void main(String[] args) { TestLogin testRegister = new TestLogin(); testRegister.login("150****8552", "admin"); } }