| | |
| | | } |
| | | |
| | | /** |
| | | * POST请求执行 并且url带参数请求 |
| | | * @return the HttpHandler response |
| | | */ |
| | | public String doPostWithParam() throws IOException { |
| | | Request request; |
| | | Request.Builder headerBuilder = new Request.Builder(); |
| | | if (headers != null && headers.size()>0){ |
| | | for (Map.Entry<String, Object> entry : headers.entrySet()){ |
| | | headerBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue())); |
| | | } |
| | | } |
| | | if (json == null || "".equals(json)){ |
| | | FormBody.Builder builder = new FormBody.Builder(); |
| | | FormBody body = builder.build(); |
| | | request = headerBuilder |
| | | .url(paramsToUrl(uri, path, params, https)) |
| | | .post(body) |
| | | .build(); |
| | | } else { |
| | | RequestBody body = RequestBody.create(MEDIA_TYPE, json); |
| | | Request.Builder builder = headerBuilder.url((https?"https://":"http://")+uri+path); |
| | | builder.header("Content-Type", "application/json;charset=UTF-8"); |
| | | request = builder.post(body).build(); |
| | | |
| | | } |
| | | Call call = getClient(timeout, timeUnit).newCall(request); |
| | | Response response = call.execute(); |
| | | return response.body().string(); |
| | | } |
| | | |
| | | /** |
| | | * POST请求执行 |
| | | * @return the HttpHandler response |
| | | */ |