| | |
| | | import java.net.MalformedURLException;
|
| | | import java.net.URL;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.commons.httpclient.Header;
|
| | |
| | | import org.apache.commons.httpclient.methods.multipart.Part;
|
| | | import org.apache.commons.httpclient.methods.multipart.StringPart;
|
| | | import org.apache.commons.io.FileUtils;
|
| | | import org.apache.http.HttpHost;
|
| | | import org.apache.http.auth.AuthScope;
|
| | | import org.apache.http.auth.UsernamePasswordCredentials;
|
| | | import org.apache.http.client.CredentialsProvider;
|
| | | import org.apache.http.client.config.RequestConfig;
|
| | | import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| | | import org.apache.http.client.methods.CloseableHttpResponse;
|
| | | import org.apache.http.client.methods.HttpPost;
|
| | | import org.apache.http.impl.client.BasicCredentialsProvider;
|
| | | import org.apache.http.impl.client.CloseableHttpClient;
|
| | | import org.apache.http.impl.client.HttpClients;
|
| | | import org.apache.http.util.EntityUtils;
|
| | | import org.yeshi.utils.entity.ProxyIP;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | |
| | | HttpClient client = new HttpClient();
|
| | | if (ipInfo != null)
|
| | | client.getHostConfiguration().setProxy(ipInfo.getIp(), ipInfo.getPort());
|
| | | client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
| | | try {
|
| | | GetMethod method = new GetMethod(url);
|
| | | if (headers != null) {
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | |
|
| | | public static String get(String url, Map<String, String> headers, ProxyIP ipInfo, String userName,
|
| | | String proxyPwd) {
|
| | | CloseableHttpClient httpclient = null;
|
| | | if (!StringUtil.isNullOrEmpty(userName)) {
|
| | | CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
| | | credsProvider.setCredentials(new AuthScope(ipInfo.getIp(), ipInfo.getPort()),
|
| | | new UsernamePasswordCredentials(userName, proxyPwd));
|
| | | httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
|
| | | } else
|
| | | HttpClients.createDefault();
|
| | | HttpHost proxy = null;
|
| | | if (ipInfo.getPort() != 0 && ipInfo.getPort() != 80) {
|
| | | proxy = new HttpHost(ipInfo.getIp(), ipInfo.getPort());
|
| | | } else
|
| | | proxy = new HttpHost(ipInfo.getIp());
|
| | | RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
|
| | | HttpPost post = new HttpPost(url);
|
| | | try {
|
| | | post.setConfig(config);
|
| | | CloseableHttpResponse response = httpclient.execute(post);
|
| | | return EntityUtils.toString(response.getEntity());
|
| | | } catch (Exception e) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public static String getAsString(String url, String fromCharset, String toCharset) {
|
| | |
| | |
|
| | | public static String post(String url, Map<String, String> map, Map<String, String> headers) {
|
| | | HttpClient client = new HttpClient();
|
| | | client.getHostConfiguration().setProxy("192.168.1.122", 8888);
|
| | | PostMethod pm = new PostMethod(url);// 创建HttpPost对象
|
| | | NameValuePair[] ns = new NameValuePair[map.keySet().size()];
|
| | | Iterator<String> its = map.keySet().iterator();
|