zoukankan      html  css  js  c++  java
  • 安卓端后台登录接口单元测试demo

    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");
    	}
    }
    

      

  • 相关阅读:
    java获取当前时间(年~~毫秒)
    python获取当前时间
    PyThon3运算符
    PyThon3中判断一个内容属于另一个内容("a" 在 “abcd”中
    PyThon3判断语句
    【BZOJ2460】元素(BJOI2011)-异或线性基+贪心
    【BZOJ3534】重建(SDOI2014)-矩阵树定理
    【BZOJ1227】虔诚的墓主人(SDOI2009)-线段树+离散化+组合数
    【BZOJ2815】灾难(ZJOI2012)-拓扑排序+建树+LCA
    【BZOJ2209】括号序列(JSOI2011)-Splay
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6758422.html
Copyright © 2011-2022 走看看