码迷,mamicode.com
首页 > 移动开发 > 详细

安卓端后台登录接口单元测试demo

时间:2017-04-24 19:50:00      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:ntp   common   add   对象   org   ace   catch   gis   commons   

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

  

安卓端后台登录接口单元测试demo

标签:ntp   common   add   对象   org   ace   catch   gis   commons   

原文地址:http://www.cnblogs.com/ipetergo/p/6758422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!