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

      

  • 相关阅读:
    WCF开发框架形成之旅---WCF的几种寄宿方式
    使用Winform程序作为WCF服务的宿主
    Winfrom 使用WCF 实现双工通讯
    WCF简单实例--用Winform启动和引用
    ASP.NET用QQ,网易发送邮件以及添加附件
    神经网络浅讲:从神经元到深度学习
    jQuery EasyUI combobox多选及赋值
    easyui combobox 带 checkbox 亲自验证
    天地图api地址
    1-3Controller之Response
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6758422.html
Copyright © 2011-2022 走看看