| | |
| | | |
| | | import com.sandu.ximon.admin.utils.request.CommonHeader; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.client.utils.URIBuilder; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URI; |
| | | import java.net.URISyntaxException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class VnnoxRequestUtil { |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static String GetWithHeader (String url, String params, CommonHeader header) { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpGet get = new HttpGet(url); |
| | | for(String key: header.keySet()) { |
| | | get.setHeader(key, header.get(key)); |
| | | } |
| | | String result = null; |
| | | try { |
| | | StringEntity s = new StringEntity(params, UTF8); |
| | | s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, |
| | | "application/json")); |
| | | HttpResponse httpResponse = client.execute(get); |
| | | InputStream inStream = httpResponse.getEntity().getContent(); |
| | | // public static String GetWithHeader (String url, String params, CommonHeader header) { |
| | | // CloseableHttpClient client = HttpClients.createDefault(); |
| | | // HttpGet get = new HttpGet(url); |
| | | // for(String key: header.keySet()) { |
| | | // get.setHeader(key, header.get(key)); |
| | | // } |
| | | // String result = null; |
| | | // try { |
| | | // StringEntity s = new StringEntity(params, UTF8); |
| | | // s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, |
| | | // "application/json")); |
| | | // HttpResponse httpResponse = client.execute(get); |
| | | // InputStream inStream = httpResponse.getEntity().getContent(); |
| | | // |
| | | // result = streamToString(inStream, UTF8); |
| | | // |
| | | // inStream.close(); |
| | | // } catch (Exception e) { |
| | | // return null; |
| | | // } |
| | | // return result; |
| | | // } |
| | | public static String GetWithHeader (String url, List<NameValuePair> urlParameters, Map<String, String> header) throws URISyntaxException { |
| | | |
| | | result = streamToString(inStream, UTF8); |
| | | |
| | | inStream.close(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | return result; |
| | | URI finalURI = new URIBuilder(url).setParameters(urlParameters).build(); |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpGet get = new HttpGet(finalURI); |
| | | for(String key: header.keySet()) { |
| | | get.setHeader(key, header.get(key)); |
| | | } |
| | | String result = null; |
| | | try { |
| | | // StringEntity s = new StringEntity(params, UTF8); |
| | | // s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, |
| | | // "application/json")); |
| | | HttpResponse httpResponse = client.execute(get); |
| | | InputStream inStream = httpResponse.getEntity().getContent(); |
| | | |
| | | result = streamToString(inStream, UTF8); |
| | | |
| | | inStream.close(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |