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;
}
相关文章:
- httpclient POST请求(urlencoded) 2022-12-23
- HttpClient之post请求 2022-12-23
- HttpClient发送Post请求,get请求 2021-12-22
- HttpClient发送Post请求 2021-11-11
- httpClient发送post请求 2021-12-06
- HttpClient post 请求实例 2022-02-19
- HttpClient 实现POST请求 2021-12-30
- HttpClient执行post请求 2022-02-04