httpclient实现Post请求

1,pom.xml

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.1</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.28</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>okhttp-urlconnection</artifactId>
            <version>2.0.0</version>
        </dependency>

2,HttpClientTest.java

package com.kafka.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import com.alibaba.fastjson.JSON;
import com.kafka.jiadu.Face;
import com.kafka.jiadu.ImageInfo;
import com.kafka.jiadu.MotorVehicle;
import com.kafka.jiadu.NonMotorVehicle;
import com.kafka.jiadu.Persion;
import com.kafka.jiadu.Scene;
import com.kafka.jiadu.Thing;
import com.kafka.jiadu.req.Image;


public class HttpClient {
    
    
    public static String httpPostWithJSON(String url,String Object) throws Exception {

        HttpPost httpPost = new HttpPost(url);
        CloseableHttpClient client = HttpClients.createDefault();
        String respContent = null;
        

        
        JSONObject jsonObject = new JSONObject(Object); 
        
        String accessLogId = jsonObject.getString("accessLogId"); //图像来源 DataSourceType
        Date dateTime=LogUtil.str2Date(jsonObject.getString("dateTime"));//拍摄时间        
        //特征来源
        String featureSource = jsonObject.getString("featureSource");
        /**
         * 视频源Url
         */
        String pvgUrl = jsonObject.getString("pvgUrl");
        /**
         * 任务ID taskid兼容pcc
         */
        String taskId = jsonObject.getString("taskId");
        
        String taskid = jsonObject.getString("taskid");
              
        Map<String,String> params = new HashMap<String,String>();
        Image image=new Image();
        
        JSONArray faceArray = jsonObject.getJSONArray("face"); 
        int age=0;
        int attractive=0;
        double confidence=0.0;
        String feature="";
        int gender=0;
        int glass=0;
        int mask=0;
        int race=0;
        int smile=0;
        int trackID=0;
        //左上 右下
        int LeftTopX=0;
        int LeftTopY=0;
        int RightBtmX=0;
        int RightBtmY=0;
        
        
        for (int j = 0; j < faceArray.length(); j++) { 
        JSONObject jsonObject2 = faceArray.getJSONObject(j); 
         age = jsonObject2.getInt("age");
       
        attractive = jsonObject2.getInt("attractive");//颜值
        /**
         * 置信度
         */
         confidence = jsonObject2.getDouble("confidence");
        /**
         * 人脸特征数据
         */
         feature = jsonObject2.getString("feature");
        /**
         * 性别0:男,1:女,-1:未知
         */
         gender = jsonObject2.getInt("gender");
        /**
         * 是否戴眼镜 眼镜:1:普通眼镜,0:太阳镜,-1:无
         */
         glass = jsonObject2.getInt("glass");
        /**
         * 是否戴面具0:没戴,1:戴,-1:未知
         */
         mask = jsonObject2.getInt("mask");
        /**
         * 种族
         */
         race = jsonObject2.getInt("race");
        /**
         * 人脸在场景图中的位置
         */
        //rect
        /**
         * 是否微笑,0:否,1:是,-1:未知
         */
         smile = jsonObject2.getInt("smile");
        /**
         * 人脸跟踪Id
         */
         trackID = jsonObject2.getInt("trackID");
        
         
         JSONArray rectArray = jsonObject2.getJSONArray("rect"); 
      
         for (int k = 0; k < rectArray.length(); k++) { 
             JSONObject jsonObject5 = rectArray.getJSONObject(j); 
             if(k==0) {
                 LeftTopX = jsonObject5.getInt("x");
                 LeftTopY=jsonObject5.getInt("y");                 
             }
             if(k==3) {
                 RightBtmX = jsonObject5.getInt("x");
                 RightBtmY=jsonObject5.getInt("y");     
             }
             
         }
        
        }
        String facePic="";
        String scenePic="";
        JSONArray imageArray = jsonObject.getJSONArray("image");   
        for (int j = 0; j < imageArray.length(); j++) { 
            JSONObject jsonObject3 = imageArray.getJSONObject(j); 
            /**
             * 人脸小图Url
             */
             facePic = jsonObject3.getString("face");
            /**
             * 目标所在场景图Url
             */
             scenePic = jsonObject3.getString("scene");
        }
      
       
        //taskParam
        String AreaId="";
        String CameraId="";
        String CameraName="";
        String playName="";
        JSONArray taskParam = jsonObject.getJSONArray("taskParam");   
        for (int j = 0; j < taskParam.length(); j++) { 
            JSONObject jsonObject4 = taskParam.getJSONObject(j); 
            
            // 区域ID
            AreaId = jsonObject4.getString("AreaId");
            // 摄像机ID
            CameraId = jsonObject4.getString("CameraId");
            // 摄像机name
             CameraName = jsonObject4.getString("CameraName");
            // 播放名称
             playName = jsonObject4.getString("playName");
        
        
        }
        
      
        
        //组装实体类
        ImageInfo imageInfo=new ImageInfo();
        imageInfo.setImageID(UUID.randomUUID().toString());
        imageInfo.setInfoKind("自动采集");
        imageInfo.setImageSource(accessLogId);
        imageInfo.setSourceVideoID("");
        imageInfo.setOriginImageID("");
        imageInfo.setEventSort("自动分析事件");
        imageInfo.setDeviceID(CameraId);
        imageInfo.setStoragePath(facePic);
        imageInfo.setFileHash("");//图像文件哈希值 使用 MD5 算法
        imageInfo.setFileFormat("");//图像文件格式
        imageInfo.setShortTime(dateTime);
        imageInfo.setTitle("");
        imageInfo.setTitleNote("");
        imageInfo.setSpeciallName("");//图像资料所属的专项名称
        imageInfo.setKeyWord("");
        imageInfo.setContentDescription("");
        imageInfo.setSubjectCharacter("");
        imageInfo.setShotPlacecode("518000");
        imageInfo.setShotPlaceFullAdress("深圳湾");
        imageInfo.setShotPlaceLongitude("");//经度
        imageInfo.setShotPlaceLatitude("");//伟度
        imageInfo.setHorizontalShotDirection("");
        imageInfo.setVerticalShotDirection("");
        imageInfo.setSecurityLevel("5");
        imageInfo.setWidth(0);
        imageInfo.setHeight(0);
        imageInfo.setCameraManufacturer("");
        imageInfo.setCameraVersion("");
        imageInfo.setApertureValue(0);
        imageInfo.setISOSensitivity(0);
        imageInfo.setFocalLength(0);
        imageInfo.setQualityGrade("");               
        imageInfo.setCollectorID("");
        imageInfo.setCollectorName("深圳");
        imageInfo.setCollectorIDType("");
        imageInfo.setCollectorOrg("");
        imageInfo.setContentDescription("");
        imageInfo.setDeviceID("");
        imageInfo.setEntryClrk("");
        imageInfo.setEntryClrkID("");
        imageInfo.setImgProcFlag("0");
       // imageInfo.setFileSize(0);
        image.setImageInfo(imageInfo);
        
        List<Face> faceList=new ArrayList<Face>();
        Face face=new Face();
        face.setFaceID(UUID.randomUUID().toString());
        face.setInfoKind("自动采集");
        face.setSourceID(accessLogId);
        face.setLeftTopX(LeftTopX);
        face.setLeftTopY(LeftTopY);
        face.setRightBtmX(RightBtmX);
        face.setRightBtmY(RightBtmY);
        face.setLocationMarkTime(dateTime);
        face.setFaceAppearTime(dateTime);
        face.setFaceDisAppearTime(dateTime);
        
        face.setAccompanyNumber(0);
        face.setAcneStain("");
        face.setAgeLowerLimit(0);
        faceList.add(face);
        image.setFaceList(faceList);
        
            List<MotorVehicle> motorVehicleList=new ArrayList<MotorVehicle>();
            MotorVehicle motorVehicle=new MotorVehicle();
            motorVehicleList.add(motorVehicle);
            image.setMotorVehicleList(motorVehicleList);
           List<NonMotorVehicle> nonMotorVehicleList=new ArrayList<NonMotorVehicle>();
           NonMotorVehicle nonMotorVehicle=new NonMotorVehicle();
           nonMotorVehicleList.add(nonMotorVehicle);
            image.setNonMotorVehicleList(nonMotorVehicleList);
           List<Persion> persionList=new ArrayList<Persion>();
           Persion persion=new Persion();
           persionList.add(persion);
            image.setPersionList(persionList);
           List<Scene> sceneList=new ArrayList<Scene>();
           Scene scene=new Scene();
           sceneList.add(scene);
            image.setSceneList(sceneList);
           List<Thing> thingList=new ArrayList<Thing>();
           Thing thing=new Thing();
           thingList.add(thing);
            image.setThingList(thingList);
           
        StringEntity entity = new StringEntity(JSON.toJSONString(image),"utf-8");//解决中文乱码问题    
        entity.setContentEncoding("UTF-8");    
        entity.setContentType("application/json");    
        httpPost.setEntity(entity);
        System.out.println();
           
        
        HttpResponse resp = client.execute(httpPost);
        if(resp.getStatusLine().getStatusCode() == 200) {
            HttpEntity he = resp.getEntity();
            respContent = EntityUtils.toString(he,"UTF-8");
        }
        return respContent;
    }
      public static void main(String[] args) throws Exception {
          String msg="{\r\n" + 
                  "\"accessLogId\":\"4b97c2b9253c438dae0ecf772843bea3\",\r\n" + 
                  "\"dateTime\":\"2018-08-08 20:04:41\",\r\n" + 
                  "\"face\":[{\r\n" + 
                  "\"age\":56,\r\n" + 
                  "\"attractive\":0,\r\n" + 
                  "\"confidence\":44.092865,\r\n" + 
                  "\"feature\":\"6lpQPBZgVL1rHJ49IK8EO3t3Jz0ofKQ9DQxKPdgTGD6PRqs7tFqAvegc8jxoNhs9a+oePW4ovLxPg189G5vDvAPuQrwU1C88VqLrvZamA73Yo+C9NeYjPdfRizyo4s49PAinPHFOpb3j8LC8eKslvYhJLD3BDzG9j10/vbRfaj0O/uW5bxP0vDaFpLtCNnk9bJB9vfhByrvWENu7zOo8vcuuD7yHu7m72beGu70FpL1JW9m8Vz6EvPGLDDwqL8m8+WLZPV1zszyzd1+9MJhqvWlWlDz/+Z67x690vUkBuT1BL/m80HGlPfVu/jwqCAu9UpmTvVkKmj2OIgw9QIqfvD2FlD3i7ic9fMh9u5vdML0ca049qLwcPUbvlDyyiG08tl3NvWwYgT2DyQY9PieIvCu0ET1+rhK9JESOPedVBjwZYGS9y12RvYhdyr1O3QE+9kQZvmj7oz1X1B49je9fvav6jzwOlGo83/WrvEs7QznZlPA7MP6JOy4HxjsToP68kssQuwMMnT0w/PY80xahPZHPAr79YX89/YonvTBrmb2mxK89Fc7yPRdYMz1lKP08CL6Eve1xLL7SlSa+CacAvti3373WCNC9lHOZvKYN3LuVFbY9T+f4PIdXJzud3H49ZeXLPGdiwz2eT7g99CFvvP0DTD0OLk+92nUSPXyawr2Vcty9XFI6u8yCQb2CWWK9jWJuvRkqlTzAffC90ChPPEq3nr36+bC8oVeMPSWfhr2yEcy9HVC4PayeRT2ZoB09h/jXPRwjrzxxc8M8k9v3vE9JGr4Dd449ap+aPaKBxTyDdeE8Uls8PRVDmLwlTGW9v3+9vY8oFb0FYkw+Fyy3PcTLnT3EV2+7z3nLPUjVbr3sEWI9IiiOPQuM97u13FK9IPYkPVn9FL6xEJ49loE+PZHgLb1aUC69t/yEOBkYqbzwd7w83+7hPMKOGjpMla69T+KbO0NDvj3lSdq6BFsJvqLzHT3X8WO8Y+yVPfofVT0P24M8qV7vPEr5r704JQ8+9tmuOxLBIT2LdsA8ghFFvEK+fDzAQ3u8L8Ovves8uzz5mxG7ztAAPkGzRz3XlC09fUqSPZcZZ72EC468WacDvZXYYT17pBk9V44cPIWdRL3EMvs75fU2PTh4U7xYwI49W4VrvRkSJz2mIJo8Rv4mvRwmNr1iggk9AWeOPcKMP70qovI7z113PUC92TxjrEy9HqUEveDBmj33ILC8eeOhPIO2MDwbXiU9ZYaDPRT+jL1VHy+8xu6vPQLLZr1HD+49TH3mPFXEuz1DILu8xKjUPdZ2/T0v+Ls8HtppvekcdT0/js48t3dDvTqy2TyjDBs9lXyMPNFJgb2l93+9U8KyvQ==\",\r\n" + 
                  "\"gender\":0,\r\n" + 
                  "\"glass\":1,\r\n" + 
                  "\"mask\":0,\r\n" + 
                  "\"race\":0,\r\n" + 
                  "\"rect\":[\r\n" + 
                  "{\r\n" + 
                  "\"x\":464,\r\n" + 
                  "\"y\":247\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":578,\r\n" + 
                  "\"y\":247\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":578,\r\n" + 
                  "\"y\":361\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":464,\r\n" + 
                  "\"y\":361\r\n" + 
                  "}\r\n" + 
                  "],\r\n" + 
                  "\"smile\":0,\r\n" + 
                  "\"trackID\":39\r\n" + 
                  "}],\r\n" + 
                  "\"featureSource\":\"PCC\",\r\n" + 
                  "\"image\":[{\r\n" + 
                  "\"face\":\"http://10.0.100.16:6551/DownLoadFile?filename=LOC:1775517865/data/20180808/11/0afb0ddc9e682e3a934629d451e981d6_2729\",\r\n" + 
                  "\"scene\":\"http://10.0.100.16:6551/DownLoadFile?filename=LOC:1775517865/data/20180808/11/0afb0ddc9e682e3a934629d451e981d6_2734\"\r\n" + 
                  "}],\r\n" + 
                  "\"pvgUrl\":\"PVG.//10.0.100.81.2100/admin:admin/av/组合2\",\r\n" + 
                  "\"taskId\":\"k64l1Z\",\r\n" + 
                  "\"taskParam\":[{\r\n" + 
                  "\"AreaId\":\"70cb6b44937d4e4084a29ef185f0e75a\",\r\n" + 
                  "\"CameraId\":\"24ab8d3d931043539b46caa80009cde8\",\r\n" + 
                  "\"CameraName\":\"组合22\",\r\n" + 
                  "\"playName\":\"av/组合2\"\r\n" + 
                  "}],\r\n" + 
                  "\"taskid\":\"k64l1Z\"\r\n" + 
                  "}";
                   
            String result = httpPostWithJSON("http://192.168.1.243:8000/VIID/Images",msg);
            System.out.println(result);
        }

}

 

3,解析对象里面嵌套对象

package com.kafka.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import com.alibaba.fastjson.JSON;
import com.kafka.jiadu.Face;
import com.kafka.jiadu.ImageInfo;
import com.kafka.jiadu.MotorVehicle;
import com.kafka.jiadu.NonMotorVehicle;
import com.kafka.jiadu.Persion;
import com.kafka.jiadu.Scene;
import com.kafka.jiadu.Thing;
import com.kafka.jiadu.req.Image;


public class HttpClientUtil {
    
 private volatile static HttpClientUtil instance;
      
     public static HttpClientUtil getInstance(){
            if(instance==null){
                synchronized (HttpClientUtil.class){
                    if(instance==null){
                        instance=new HttpClientUtil();
                    }
                }
            }
            return instance;
        }
    
    
    public static String httpPostWithJSON(String url,String Object) throws Exception {

        HttpPost httpPost = new HttpPost(url);
        CloseableHttpClient client = HttpClients.createDefault();
        String respContent = null;
        

        
        JSONObject jsonObject = new JSONObject(Object); 
        
        String accessLogId = jsonObject.getString("accessLogId"); //图像来源 DataSourceType
        Date dateTime=LogUtil.str2Date(jsonObject.getString("dateTime"));//拍摄时间        
        //特征来源
        String featureSource = jsonObject.getString("featureSource");
       
        /**
         * 任务ID taskid兼容pcc
         */
        String taskId = jsonObject.getString("taskId");
        
        String taskid = jsonObject.getString("taskid");
       
        int age=jsonObject.getJSONObject("face").getInt("age");
              
        /***
         * 颜值
         */
        int attractive=jsonObject.getJSONObject("face").getInt("attractive");
        
        /**
         * 置信度
         */
        double confidence=jsonObject.getJSONObject("face").getInt("confidence");       
        /**
         * 性别0:男,1:女,-1:未知
         */
        int  gender = jsonObject.getJSONObject("face").getInt("gender");
        /**
         * 是否戴眼镜 眼镜:1:普通眼镜,0:太阳镜,-1:无
         */
        int   glass = jsonObject.getJSONObject("face").getInt("glass");
        /**
         * 是否戴面具0:没戴,1:戴,-1:未知
         */
        int  mask = jsonObject.getJSONObject("face").getInt("mask");
        /**
         * 种族
         */
        int   race = jsonObject.getJSONObject("face").getInt("race");
    
        /**
         * 是否微笑,0:否,1:是,-1:未知
         */
        int  smile = jsonObject.getJSONObject("face").getInt("smile");
        /**
         * 人脸跟踪Id
         */
        int  trackID = jsonObject.getJSONObject("face").getInt("trackID");
        
        /**
         * 人脸小图Url
         */
        String   facePic = jsonObject.getJSONObject("image").getString("face");
        /**
         * 目标所在场景图Url
         */
        String   scenePic = jsonObject.getJSONObject("image").getString("scene");
        
        // 区域ID
        String  AreaId = jsonObject.getJSONObject("taskParam").getString("AreaId");
        // 摄像机ID
        String  CameraId = jsonObject.getJSONObject("taskParam").getString("CameraId");
        // 摄像机name
        String   CameraName = jsonObject.getJSONObject("taskParam").getString("CameraName");
        // 播放名称
        String  playName = jsonObject.getJSONObject("taskParam").getString("playName");
        
        //左上 右下
        int LeftTopX=0;
        int LeftTopY=0;
        int RightBtmX=0;
        int RightBtmY=0;
        
        /*   JSONArray rectArray = jsonObject.getJSONObject("face").getJSONArray("rect"); 
      
         for (int i = 0; i < rectArray.length(); i++) { 
             JSONObject jsonObject1 = rectArray.getJSONObject(i); 
             if(i==0) {
                 LeftTopX = jsonObject1.getInt("x");
                 LeftTopY=jsonObject1.getInt("y");                 
             }
             if(i==3) {
                 RightBtmX = jsonObject1.getInt("x");
                 RightBtmY=jsonObject1.getInt("y");     
             }
             
         }
         */
        
        
        
        
        Map<String,String> params = new HashMap<String,String>();
        Image image=new Image();
         
        //组装实体类
        ImageInfo imageInfo=new ImageInfo();
        imageInfo.setImageID(UUID.randomUUID().toString());
        imageInfo.setInfoKind("自动采集");
        imageInfo.setImageSource(accessLogId);
        imageInfo.setSourceVideoID("");
        imageInfo.setOriginImageID("");
        imageInfo.setEventSort("自动分析事件");
        imageInfo.setDeviceID(CameraId);
        imageInfo.setStoragePath(facePic);
        imageInfo.setFileHash("");//图像文件哈希值 使用 MD5 算法
        imageInfo.setFileFormat("");//图像文件格式
        imageInfo.setShortTime(dateTime);
        imageInfo.setTitle("");
        imageInfo.setTitleNote("");
        imageInfo.setSpeciallName("");//图像资料所属的专项名称
        imageInfo.setKeyWord("");
        imageInfo.setContentDescription("");
        imageInfo.setSubjectCharacter("");
        imageInfo.setShotPlacecode("518000");
        imageInfo.setShotPlaceFullAdress("深圳湾");
        imageInfo.setShotPlaceLongitude("114.06667000");//经度
        imageInfo.setShotPlaceLatitude("22.61667000");//伟度
        imageInfo.setHorizontalShotDirection("");
        imageInfo.setVerticalShotDirection("");
        imageInfo.setSecurityLevel("5");
        imageInfo.setWidth(0);
        imageInfo.setHeight(0);
        imageInfo.setCameraManufacturer("");
        imageInfo.setCameraVersion("");
        imageInfo.setApertureValue(0);
        imageInfo.setISOSensitivity(0);
        imageInfo.setFocalLength(0);
        imageInfo.setQualityGrade("");               
        imageInfo.setCollectorID("");
        imageInfo.setCollectorName(CameraName);
        imageInfo.setCollectorIDType("");
        imageInfo.setCollectorOrg("");
        imageInfo.setContentDescription("");
        imageInfo.setDeviceID("");
        imageInfo.setEntryClrk("");
        imageInfo.setEntryClrkID("");
        imageInfo.setImgProcFlag("0");
       // imageInfo.setFileSize(0);
        image.setImageInfo(imageInfo);
        
        List<Face> faceList=new ArrayList<Face>();
        Face face=new Face();
        face.setFaceID(UUID.randomUUID().toString());
        face.setInfoKind("自动采集");
        face.setSourceID(accessLogId);
        face.setLeftTopX(LeftTopX);
        face.setLeftTopY(LeftTopY);
        face.setRightBtmX(RightBtmX);
        face.setRightBtmY(RightBtmY);
        face.setLocationMarkTime(dateTime);
        face.setFaceAppearTime(dateTime);
        face.setFaceDisAppearTime(dateTime);
        face.setPhysicalFeature("");
        face.setAccompanyNumber(0);
        face.setAcneStain("");
        face.setAgeLowerLimit(0);
        face.setGenderCode(gender+"");
        face.setEthicCode(race+"");
        face.setFacialFeature(smile+"");
        face.setAgeUpLimit(age);
        face.setAgeLowerLimit(age);
        faceList.add(face);
        image.setFaceList(faceList);
        
            List<MotorVehicle> motorVehicleList=new ArrayList<MotorVehicle>();
            MotorVehicle motorVehicle=new MotorVehicle();
            motorVehicleList.add(motorVehicle);
            image.setMotorVehicleList(motorVehicleList);
           List<NonMotorVehicle> nonMotorVehicleList=new ArrayList<NonMotorVehicle>();
           NonMotorVehicle nonMotorVehicle=new NonMotorVehicle();
           nonMotorVehicleList.add(nonMotorVehicle);
            image.setNonMotorVehicleList(nonMotorVehicleList);
           List<Persion> persionList=new ArrayList<Persion>();
           Persion persion=new Persion();
           persion.setPersonID(UUID.randomUUID().toString());
           persion.setInfoKind("自动采集");
           persion.setDeviceID(CameraId);
           persion.setSourceID(accessLogId);
           persion.setLeftTopX(LeftTopX);
           persion.setLeftTopY(LeftTopY);
           persion.setRightBtmX(RightBtmX);
           persion.setRightBtmY(RightBtmY);
           persion.setLocationMarkTime(dateTime);
           persion.setPersonAppearTime(dateTime);
           persion.setPersonDisAppearTime(dateTime);
           persion.setPhysicalFeature("");
           persion.setAgeLowerLimit(age);
           persion.setAgeUpLimit(age);
           persion.setGenderCode(gender+"");
           persion.setEthicCode(race+"");
           persion.setFacialFeature(smile+"");
           persionList.add(persion);
            image.setPersionList(persionList);
           List<Scene> sceneList=new ArrayList<Scene>();
           Scene scene=new Scene();
           scene.setSceneID(UUID.randomUUID().toString());
           scene.setInfoKind("自动采集");
           scene.setSourceID(accessLogId);           
           scene.setPlaceType(AreaId);
           scene.setIllustration(scenePic);
           sceneList.add(scene);
            image.setSceneList(sceneList);
           List<Thing> thingList=new ArrayList<Thing>();
           Thing thing=new Thing();
           thingList.add(thing);
            image.setThingList(thingList);
           
        StringEntity entity = new StringEntity(JSON.toJSONString(image),"utf-8");//解决中文乱码问题    
        entity.setContentEncoding("UTF-8");    
        entity.setContentType("application/json");    
        httpPost.setEntity(entity);
        System.out.println();
           
        
        HttpResponse resp = client.execute(httpPost);
        if(resp.getStatusLine().getStatusCode() == 200) {
            HttpEntity he = resp.getEntity();
            respContent = EntityUtils.toString(he,"UTF-8");
        }
        return respContent;
    }
      public static void main(String[] args) throws Exception {
                          
          String msg="{\r\n" + 
                  "\"accessLogId\":\"4b97c2b9253c438dae0ecf772843bea3\",\r\n" + 
                  "\"dateTime\":\"2018-08-08 20:04:41\",\r\n" + 
                  "\"face\":{\r\n" + 
                  "\"age\":56,\r\n" + 
                  "\"attractive\":0,\r\n" + 
                  "\"confidence\":44.092865,\r\n" + 
                  "\"feature\":\"6lpQPBZgVL1rHJ49IK8EO3t3Jz0ofKQ9DQxKPdgTGD6PRqs7tFqAvegc8jxoNhs9a+oePW4ovLxPg189G5vDvAPuQrwU1C88VqLrvZamA73Yo+C9NeYjPdfRizyo4s49PAinPHFOpb3j8LC8eKslvYhJLD3BDzG9j10/vbRfaj0O/uW5bxP0vDaFpLtCNnk9bJB9vfhByrvWENu7zOo8vcuuD7yHu7m72beGu70FpL1JW9m8Vz6EvPGLDDwqL8m8+WLZPV1zszyzd1+9MJhqvWlWlDz/+Z67x690vUkBuT1BL/m80HGlPfVu/jwqCAu9UpmTvVkKmj2OIgw9QIqfvD2FlD3i7ic9fMh9u5vdML0ca049qLwcPUbvlDyyiG08tl3NvWwYgT2DyQY9PieIvCu0ET1+rhK9JESOPedVBjwZYGS9y12RvYhdyr1O3QE+9kQZvmj7oz1X1B49je9fvav6jzwOlGo83/WrvEs7QznZlPA7MP6JOy4HxjsToP68kssQuwMMnT0w/PY80xahPZHPAr79YX89/YonvTBrmb2mxK89Fc7yPRdYMz1lKP08CL6Eve1xLL7SlSa+CacAvti3373WCNC9lHOZvKYN3LuVFbY9T+f4PIdXJzud3H49ZeXLPGdiwz2eT7g99CFvvP0DTD0OLk+92nUSPXyawr2Vcty9XFI6u8yCQb2CWWK9jWJuvRkqlTzAffC90ChPPEq3nr36+bC8oVeMPSWfhr2yEcy9HVC4PayeRT2ZoB09h/jXPRwjrzxxc8M8k9v3vE9JGr4Dd449ap+aPaKBxTyDdeE8Uls8PRVDmLwlTGW9v3+9vY8oFb0FYkw+Fyy3PcTLnT3EV2+7z3nLPUjVbr3sEWI9IiiOPQuM97u13FK9IPYkPVn9FL6xEJ49loE+PZHgLb1aUC69t/yEOBkYqbzwd7w83+7hPMKOGjpMla69T+KbO0NDvj3lSdq6BFsJvqLzHT3X8WO8Y+yVPfofVT0P24M8qV7vPEr5r704JQ8+9tmuOxLBIT2LdsA8ghFFvEK+fDzAQ3u8L8Ovves8uzz5mxG7ztAAPkGzRz3XlC09fUqSPZcZZ72EC468WacDvZXYYT17pBk9V44cPIWdRL3EMvs75fU2PTh4U7xYwI49W4VrvRkSJz2mIJo8Rv4mvRwmNr1iggk9AWeOPcKMP70qovI7z113PUC92TxjrEy9HqUEveDBmj33ILC8eeOhPIO2MDwbXiU9ZYaDPRT+jL1VHy+8xu6vPQLLZr1HD+49TH3mPFXEuz1DILu8xKjUPdZ2/T0v+Ls8HtppvekcdT0/js48t3dDvTqy2TyjDBs9lXyMPNFJgb2l93+9U8KyvQ==\",\r\n" + 
                  "\"gender\":0,\r\n" + 
                  "\"glass\":1,\r\n" + 
                  "\"mask\":0,\r\n" + 
                  "\"race\":0,\r\n" + 
                  "\"rect\":[\r\n" + 
                  "{\r\n" + 
                  "\"x\":464,\r\n" + 
                  "\"y\":247\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":578,\r\n" + 
                  "\"y\":247\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":578,\r\n" + 
                  "\"y\":361\r\n" + 
                  "},\r\n" + 
                  "{\r\n" + 
                  "\"x\":464,\r\n" + 
                  "\"y\":361\r\n" + 
                  "}\r\n" + 
                  "],\r\n" + 
                  "\"smile\":0,\r\n" + 
                  "\"trackID\":39\r\n" + 
                  "},\r\n" + 
                  "\"featureSource\":\"PCC\",\r\n" + 
                  "\"image\":{\r\n" + 
                  "\"face\":\"http://10.0.100.16:6551/DownLoadFile?filename=LOC:1775517865/data/20180808/11/0afb0ddc9e682e3a934629d451e981d6_2729\",\r\n" + 
                  "\"scene\":\"http://10.0.100.16:6551/DownLoadFile?filename=LOC:1775517865/data/20180808/11/0afb0ddc9e682e3a934629d451e981d6_2734\"\r\n" + 
                  "},\r\n" + 
                  "\"pvgUrl\":\"PVG.//10.0.100.81.2100/admin:admin/av/组合2\",\r\n" + 
                  "\"taskId\":\"k64l1Z\",\r\n" + 
                  "\"taskParam\":{\r\n" + 
                  "\"AreaId\":\"70cb6b44937d4e4084a29ef185f0e75a\",\r\n" + 
                  "\"CameraId\":\"24ab8d3d931043539b46caa80009cde8\",\r\n" + 
                  "\"CameraName\":\"组合22\",\r\n" + 
                  "\"playName\":\"av/组合2\"\r\n" + 
                  "},\r\n" + 
                  "\"taskid\":\"k64l1Z\"\r\n" + 
                  "}";
            String result = httpPostWithJSON("http://192.168.1.243:8000/VIID/Images",msg);
            System.out.println(result);
        }

}

 

posted on 2018-08-16 09:16  让代码飞  阅读(601)  评论(0)    收藏  举报

导航

一款免费在线思维导图工具推荐:https://www.processon.com/i/593e9a29e4b0898669edaf7f?full_name=python