@@ -1,5 +1,6 @@ | |||||
package me.chanjar.weixin.mp.util.http.apache; | package me.chanjar.weixin.mp.util.http.apache; | ||||
import com.google.common.collect.ImmutableMap; | |||||
import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||
@@ -43,9 +44,7 @@ public class ApacheMaterialNewsInfoRequestExecutor | |||||
httpPost.setConfig(config); | httpPost.setConfig(config); | ||||
} | } | ||||
Map<String, String> params = new HashMap<>(); | |||||
params.put("media_id", materialId); | |||||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); | |||||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)))); | |||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { | try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { | ||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | ||||
this.logger.debug("响应原始数据:{}", responseContent); | this.logger.debug("响应原始数据:{}", responseContent); | ||||
@@ -1,5 +1,6 @@ | |||||
package me.chanjar.weixin.mp.util.http.jodd; | package me.chanjar.weixin.mp.util.http.jodd; | ||||
import com.google.common.collect.ImmutableMap; | |||||
import jodd.http.HttpConnectionProvider; | import jodd.http.HttpConnectionProvider; | ||||
import jodd.http.HttpRequest; | import jodd.http.HttpRequest; | ||||
import jodd.http.HttpResponse; | import jodd.http.HttpResponse; | ||||
@@ -9,6 +10,7 @@ import jodd.util.StringPool; | |||||
import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | ||||
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; | import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; | ||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
@@ -28,13 +30,13 @@ public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequest | |||||
@Override | @Override | ||||
public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException { | public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException { | ||||
HttpRequest request = HttpRequest.post(uri); | |||||
if (requestHttp.getRequestHttpProxy() != null) { | if (requestHttp.getRequestHttpProxy() != null) { | ||||
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy()); | requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy()); | ||||
} | } | ||||
request.withConnectionProvider(requestHttp.getRequestHttpClient()); | |||||
request.query("media_id", materialId); | |||||
HttpRequest request = HttpRequest.post(uri) | |||||
.withConnectionProvider(requestHttp.getRequestHttpClient()) | |||||
.body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId))); | |||||
HttpResponse response = request.send(); | HttpResponse response = request.send(); | ||||
response.charset(StringPool.UTF_8); | response.charset(StringPool.UTF_8); | ||||
@@ -1,9 +1,11 @@ | |||||
package me.chanjar.weixin.mp.util.http.okhttp; | package me.chanjar.weixin.mp.util.http.okhttp; | ||||
import com.google.common.collect.ImmutableMap; | |||||
import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | ||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | ||||
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; | import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; | ||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
@@ -28,7 +30,8 @@ public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoReque | |||||
//得到httpClient | //得到httpClient | ||||
OkHttpClient client = requestHttp.getRequestHttpClient(); | OkHttpClient client = requestHttp.getRequestHttpClient(); | ||||
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build(); | |||||
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), | |||||
WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId))); | |||||
Request request = new Request.Builder().url(uri).post(requestBody).build(); | Request request = new Request.Builder().url(uri).post(requestBody).build(); | ||||
Response response = client.newCall(request).execute(); | Response response = client.newCall(request).execute(); | ||||