zoukankan      html  css  js  c++  java
  • Httpclient post请求

     CloseableHttpClient httpclient = HttpClients.createDefault();
    String url = "https://ml.yiche.com/test_recognize/rest/v1/face_async_register";
    HttpPost httpPost = new HttpPost(url);
    httpPost.addHeader("charset", HTTP.UTF_8);
    httpPost.setHeader("Content-Type",
    "application/x-www-form-urlencoded; charset=utf-8");

    NameValuePair accessKeyIdPair = new BasicNameValuePair("accessKeyId", "lottery_register");
    NameValuePair userIdPair = new BasicNameValuePair("userId", userId);
    NameValuePair paramPair = new BasicNameValuePair("userInfo", param);
    NameValuePair imagePair = new BasicNameValuePair("image", imageBase64Data);
    NameValuePair imgUrlPair = new BasicNameValuePair("imgUrl", "lottery");
    List<NameValuePair> nameValuePairList = Lists.newArrayList(accessKeyIdPair
    , userIdPair
    , paramPair
    , imagePair, imgUrlPair);


    UrlEncodedFormEntity httpEntity = new UrlEncodedFormEntity(nameValuePairList);
    httpPost.setEntity(httpEntity);
    // 执行post请求.
    CloseableHttpResponse response = httpclient.execute(httpPost);

    if (Objects.nonNull(response) && response.getStatusLine()
    .getStatusCode() == HttpStatus.OK.value()) {

    String reponseLine = EntityUtils.toString(response.getEntity());
    if (!StringUtils.isEmpty(reponseLine)) {
    JSONObject jsonObject = JSON.parseObject(reponseLine);

    if (Objects.nonNull(jsonObject)) {
    if (jsonObject.getInteger("code") == 0) {
    return 1;
    }
    }
    }
    }

    return 0;
    }
  • 相关阅读:
    1041. 困于环中的机器人
    95. 不同的二叉搜索树 II
    LeetCode945:使数组唯一的最小增量
    LeetCode:925.长按键入
    LeetCode:926. 将字符串翻转到单调递增
    InteliJ 安装PlantUML插件
    CodeBlock换肤
    正则表达式验证手机号和座机号
    C#中使用反射遍历一个对象属性和值以及百分数
    c#中@的用法
  • 原文地址:https://www.cnblogs.com/liubaihui/p/8126697.html
Copyright © 2011-2022 走看看