小程序
小游戏
企业微信
微信支付
扫描小程序码分享
如果还是要检测,img_seq_check接口该怎么调用?不知道怎么设置media字段,可以给个样例吗?
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
public
String execute(CloseableHttpClient httpclient, String url, InputStream imgstream)
throws
IOException {
HttpPost httpost =
new
HttpPost(url);
HttpEntity entry = MultipartEntityBuilder
.create()
.addBinaryBody(
"media"
,imgstream)
.setMode(HttpMultipartMode.RFC6532)
.build();
httpost.setEntity(entry);
try
(CloseableHttpResponse response = httpclient.execute(httpost)) {
String responseContent = resputf8handle.handleResponse(response);
//如果请求发生错误,抛出异常
ObjectMapper mapper =
ObjectMapper();
JsonNode node = mapper.readTree(responseContent);
if
(node.get(
"errcode"
) !=
null
&& !(node.get(
).asInt() ==
0
)) {
//WxError error = WxError.fromJson(responseContent);
//throw new Exception(responseContent);
}
return
responseContent;
把网络图片读到InputStream并缩放到1000x1000以下尺寸,然后用上面代码Post,得到下面错误:
RetryExec.java:97) I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.weixin.qq.com:443: Connection reset by peer: socket write error
还缺什么吗?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
Java代码片段
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
public
String execute(CloseableHttpClient httpclient, String url, InputStream imgstream)
throws
IOException {
HttpPost httpost =
new
HttpPost(url);
HttpEntity entry = MultipartEntityBuilder
.create()
.addBinaryBody(
"media"
,imgstream)
.setMode(HttpMultipartMode.RFC6532)
.build();
httpost.setEntity(entry);
try
(CloseableHttpResponse response = httpclient.execute(httpost)) {
String responseContent = resputf8handle.handleResponse(response);
//如果请求发生错误,抛出异常
ObjectMapper mapper =
new
ObjectMapper();
JsonNode node = mapper.readTree(responseContent);
if
(node.get(
"errcode"
) !=
null
&& !(node.get(
"errcode"
).asInt() ==
0
)) {
//WxError error = WxError.fromJson(responseContent);
//throw new Exception(responseContent);
}
return
responseContent;
}
}
}
把网络图片读到InputStream并缩放到1000x1000以下尺寸,然后用上面代码Post,得到下面错误:
RetryExec.java:97) I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.weixin.qq.com:443: Connection reset by peer: socket write error
还缺什么吗?
Java代码片段