java 发送post请求

//创建post请求对象
        HttpPost post = new HttpPost("https://uat-gateway.qinlinkeji.com/open-plugin/login/v1/clientLogin");
        String result = "";
        try {
            //添加参数
            StringEntity postingString = new StringEntity(str2);
            post.setEntity(postingString);
            post.setHeader("Content-type", "application/json");
            //添加请求头参数
            post.addHeader("version", "v2");
            post.addHeader("appid", "appid");
            post.addHeader("nonce", String.valueOf(nonce));
            post.addHeader("timestamp", String.valueOf(sj));
            post.addHeader("sign", signStr);

            CloseableHttpClient client = HttpClients.createDefault();
            //启动执行请求,并获得返回值
            CloseableHttpResponse response = client.execute(post);
            //得到返回的entity对象
            HttpEntity entity = response.getEntity();
            //把实体对象转换为string
            result = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e1) {
            e1.printStackTrace();
        }
//        Object[] ob = {signStr, success, sign, result,searchMap,mobile};
        Object[] ob = {result,mobile};
        System.out.println(result);
        return new Result(true, StatusCode.OK,"查询成功",ob);

 

 

你可能感兴趣的:(java,java)