// Path: faceplusplus_api_v2/com/xiaoying/faceplusplus/api/config/UrlConfig.java
// public class UrlConfig {
// 	
// 	public static final String CHART_SET = "UTF-8";
// 
// 	public static final String BASE_URL = "https://apicn.faceplusplus.com/v2";
// 	
// 	//Face
// 	public static final String PATH_DETECT = "/detection/detect";
// 	
// 	//Person
// 	public static final String PATH_PERSON_CREATE = "/person/create";
// 	
// 	public static final String PATH_PERSON_DELETE = "/person/delete";
// 	
// 	public static final String PATH_PERSON_ADD_FACE = "/person/add_face";
// 	
// 	public static final String PATH_PERSON_REMOVE_FACE = "/person/remove_face";
// 	
// 	public static final String PATH_PERSON_SET_INFO = "/person/set_info";
// 	
// 	public static final String PATH_PERSON_GET_INFO = "/person/get_info";
// 	
// 	//Group
// 	public static final String PATH_GROUP_CREATE = "/group/create";
// 	
// 	public static final String PATH_GROUP_DELETE = "/group/delete";
// 	
// 	public static final String PATH_GROUP_ADD_PERSON = "/group/add_person";
// 	
// 	public static final String PATH_GROUP_REMOVE_PERSON = "/group/remove_person";
// 	
// 	public static final String PATH_GROUP_SET_INFO = "/group/set_info";
// 	
// 	public static final String PATH_GROUP_GET_INFO = "/group/get_info";
// 	
// 	//Faceset
// 	public static final String PATH_FACESET_CREATE = "/faceset/create";
// 
// 	public static final String PATH_FACESET_DELETE = "/faceset/delete";
// 	
// 	public static final String PATH_FACESET_ADD_FACE = "/faceset/add_face";
// 	
// 	public static final String PATH_FACESET_REMOVE_FACE = "/faceset/remove_face";
// 	
// 	public static final String PATH_FACESET_SET_INFO = "/faceset/set_info";
// 	
// 	public static final String PATH_FACESET_GET_INFO = "/faceset/get_info";
// 
// 	//Grouping
// 	public static final String PATH_GROUPING = "/grouping/grouping";
// 	
// 	//Info
// 	public static final String PATH_INFO_GET_IMAGE = "/info/get_image";
// 	
// 	public static final String PATH_INFO_GET_FACE = "/info/get_face";
// 	
// 	public static final String PATH_INFO_GET_PERSON_LIST = "/info/get_person_list";
// 	
// 	public static final String PATH_INFO_GET_FACESET_LIST = "/info/get_faceset_list";
// 	
// 	public static final String PATH_INFO_GET_GROUP_LIST = "/info/get_group_list";
// 	
// 	public static final String PATH_INFO_GET_SESSION = "/info/get_session";
// 	
// 	public static final String PATH_INFO_GET_QUOTA = "/info/get_quota";
// 	
// 	public static final String PATH_INFO_GET_APP = "/info/get_app";
// 	
// 	//train
// 	public static final String PATH_TRAIN_VERIFY = "/train/verify";
// 
// 	public static final String PATH_TRAIN_SEARCH = "/train/search";
// 	
// 	public static final String PATH_TRAIN_IDENTIFY = "/train/identify";
// 	
// 	//recognition
// 	public static final String PATH_RECOGNITION_COMPARE = "/recognition/compare";
// 	
// 	public static final String PATH_RECOGNITION_VERIFY = "/recognition/verify";
// 	
// 	public static final String PATH_RECOGNITION_SEARCH = "/recognition/search";
// 	
// 	public static final String PATH_RECOGNITION_IDENTIFY = "/recognition/identify";
// 	
// }


import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Set;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import com.xiaoying.faceplusplus.api.config.UrlConfig;
/*
 * 文件名：HttpUtil.java
 * 版权：<版权>
 * 描述：<描述>
 * 创建人：xiaoying
 * 创建时间：2013-5-10
 * 修改人：xiaoying
 * 修改时间：2013-5-10
 * 版本：v1.0
 */
package com.xiaoying.faceplusplus.api.utils;




/**
 * 功能：网络数据传输工具类
 * @author xiaoying
 */
public class HttpUtil {
	
	
	public static HttpResponse doPost(String actionPath, Map<String, Object> params) throws ClientProtocolException, IOException {
		DefaultHttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost(UrlConfig.BASE_URL + actionPath);
		MultipartEntity mulEntity = new MultipartEntity();
		Set<String> keys = params.keySet();
		for (String key : keys) {
			Object obj = params.get(key);
			if (obj instanceof File && obj != null) {
				mulEntity.addPart(key, new FileBody((File) obj));
			} else {
				if(obj != null && !StringUtil.isEmpty(obj.toString())) {
// Path: faceplusplus_api_v2/com/xiaoying/faceplusplus/api/config/UrlConfig.java
// public class UrlConfig {
// 	
// 	public static final String CHART_SET = "UTF-8";
// 
// 	public static final String BASE_URL = "https://apicn.faceplusplus.com/v2";
// 	
// 	//Face
// 	public static final String PATH_DETECT = "/detection/detect";
// 	
// 	//Person
// 	public static final String PATH_PERSON_CREATE = "/person/create";
// 	
// 	public static final String PATH_PERSON_DELETE = "/person/delete";
// 	
// 	public static final String PATH_PERSON_ADD_FACE = "/person/add_face";
// 	
// 	public static final String PATH_PERSON_REMOVE_FACE = "/person/remove_face";
// 	
// 	public static final String PATH_PERSON_SET_INFO = "/person/set_info";
// 	
// 	public static final String PATH_PERSON_GET_INFO = "/person/get_info";
// 	
// 	//Group
// 	public static final String PATH_GROUP_CREATE = "/group/create";
// 	
// 	public static final String PATH_GROUP_DELETE = "/group/delete";
// 	
// 	public static final String PATH_GROUP_ADD_PERSON = "/group/add_person";
// 	
// 	public static final String PATH_GROUP_REMOVE_PERSON = "/group/remove_person";
// 	
// 	public static final String PATH_GROUP_SET_INFO = "/group/set_info";
// 	
// 	public static final String PATH_GROUP_GET_INFO = "/group/get_info";
// 	
// 	//Faceset
// 	public static final String PATH_FACESET_CREATE = "/faceset/create";
// 
// 	public static final String PATH_FACESET_DELETE = "/faceset/delete";
// 	
// 	public static final String PATH_FACESET_ADD_FACE = "/faceset/add_face";
// 	
// 	public static final String PATH_FACESET_REMOVE_FACE = "/faceset/remove_face";
// 	
// 	public static final String PATH_FACESET_SET_INFO = "/faceset/set_info";
// 	
// 	public static final String PATH_FACESET_GET_INFO = "/faceset/get_info";
// 
// 	//Grouping
// 	public static final String PATH_GROUPING = "/grouping/grouping";
// 	
// 	//Info
// 	public static final String PATH_INFO_GET_IMAGE = "/info/get_image";
// 	
// 	public static final String PATH_INFO_GET_FACE = "/info/get_face";
// 	
// 	public static final String PATH_INFO_GET_PERSON_LIST = "/info/get_person_list";
// 	
// 	public static final String PATH_INFO_GET_FACESET_LIST = "/info/get_faceset_list";
// 	
// 	public static final String PATH_INFO_GET_GROUP_LIST = "/info/get_group_list";
// 	
// 	public static final String PATH_INFO_GET_SESSION = "/info/get_session";
// 	
// 	public static final String PATH_INFO_GET_QUOTA = "/info/get_quota";
// 	
// 	public static final String PATH_INFO_GET_APP = "/info/get_app";
// 	
// 	//train
// 	public static final String PATH_TRAIN_VERIFY = "/train/verify";
// 
// 	public static final String PATH_TRAIN_SEARCH = "/train/search";
// 	
// 	public static final String PATH_TRAIN_IDENTIFY = "/train/identify";
// 	
// 	//recognition
// 	public static final String PATH_RECOGNITION_COMPARE = "/recognition/compare";
// 	
// 	public static final String PATH_RECOGNITION_VERIFY = "/recognition/verify";
// 	
// 	public static final String PATH_RECOGNITION_SEARCH = "/recognition/search";
// 	
// 	public static final String PATH_RECOGNITION_IDENTIFY = "/recognition/identify";
// 	
// }


// Path: faceplusplus_api_v2/com/xiaoying/faceplusplus/api/utils/HttpUtil.java
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Set;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import com.xiaoying.faceplusplus.api.config.UrlConfig;

/*
 * 文件名：HttpUtil.java
 * 版权：<版权>
 * 描述：<描述>
 * 创建人：xiaoying
 * 创建时间：2013-5-10
 * 修改人：xiaoying
 * 修改时间：2013-5-10
 * 版本：v1.0
 */
package com.xiaoying.faceplusplus.api.utils;




/**
 * 功能：网络数据传输工具类
 * @author xiaoying
 */
public class HttpUtil {
	
	
	public static HttpResponse doPost(String actionPath, Map<String, Object> params) throws ClientProtocolException, IOException {
		DefaultHttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost(UrlConfig.BASE_URL + actionPath);
		MultipartEntity mulEntity = new MultipartEntity();
		Set<String> keys = params.keySet();
		for (String key : keys) {
			Object obj = params.get(key);
			if (obj instanceof File && obj != null) {
				mulEntity.addPart(key, new FileBody((File) obj));
			} else {
				if(obj != null && !StringUtil.isEmpty(obj.toString())) {
					mulEntity.addPart(key, new StringBody(obj.toString(), Charset.forName(UrlConfig.CHART_SET)));