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;
    }
  • 相关阅读:
    SyntaxError: Non-ASCII character 'xe7' in file解决方法
    python实现微信打飞机游戏
    ubuntu 系统出错一览
    MVC的特点
    架构
    策略模式
    bin
    使用XSLT实现Word下载
    <a>标签的href属性
    call-template和apply-templates
  • 原文地址:https://www.cnblogs.com/liubaihui/p/8126697.html
Copyright © 2011-2022 走看看