post请求失败
今天写接口,在联调。我要调用队友php的接口数据,而要求使用post请求。
而当我写好代码,跑起来,却说我没有传参。最后发现,是因为我使用的工具类的方法是把参数拼到了url后面,而不是放到请求体中,所以导致拿不到数据。
我用的工具类的方法:
public static String doPost(String host, String path,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
HttpResponse response = httpClient.execute(request);
int respCode = response.getStatusLine().getStatusCode();
if(respCode!=200){
return null;
}
return EntityUtils.toString(response.getEntity());
}
private static HttpClient wrapClient(String host) {
HttpClient httpClient = new DefaultHttpClient();
if (host.startsWith("https://")) {
sslClient(httpClient);
}
return httpClient;
}
private static void sslClient(HttpClient httpClient) {
try {
SSL