use of com.zhy.http.okhttp.builder.PostFormBuilder in project JustAndroid by chinaltz.
the class OKHttpAdapter method sendRequest.
@Override
public void sendRequest(WXRequest request, final OnHttpListener listener) {
PostFormBuilder postFormBuilder = null;
GetBuilder getBuilder = null;
if ("POST".equals(request.method) || "PUT".equals(request.method) || "PATCH".equals(request.method)) {
postFormBuilder = OkHttpUtils.post().url(request.url);
} else {
getBuilder = OkHttpUtils.get().url(request.url);
}
if (request.paramMap != null) {
Set<String> keySets = request.paramMap.keySet();
for (String key : keySets) {
if (postFormBuilder != null) {
postFormBuilder.addParams(key, request.paramMap.get(key));
}
if (getBuilder != null) {
getBuilder.addParams(key, request.paramMap.get(key));
}
}
}
if (getBuilder != null) {
getBuilder.build().execute(new Callback() {
@Override
public Object parseNetworkResponse(Response response, int id) throws Exception {
WXResponse wxResponse = new WXResponse();
wxResponse.statusCode = String.valueOf(response.code());
wxResponse.data = response.body().string();
if (listener != null) {
listener.onHttpFinish(wxResponse);
}
return null;
}
@Override
public void onError(Call call, Exception e, int id) {
Log.d("mataa", e.getLocalizedMessage());
}
@Override
public void onResponse(Object response, int id) {
}
});
}
}
Aggregations