基于SpringBoot的AI游戏对战平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
1.3 KiB

package com.kob.backend.service.impl.user.account.acwing.utils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
public class HttpClientUtil {
public static String get(String url, List<NameValuePair> params) {
URIBuilder uriBuilder = null;
try {
uriBuilder = new URIBuilder(url);
} catch (URISyntaxException e) {
e.printStackTrace();
return null;
}
uriBuilder.setParameters(params);
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(uriBuilder.build());
CloseableHttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity);
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
return null;
}
}
}