当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest类代码示例

本文整理汇总了Java中com.github.kevinsawicki.http.HttpRequest的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest类的具体用法?Java HttpRequest怎么用?Java HttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequest类属于com.github.kevinsawicki.http包,在下文中一共展示了HttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
public static void main(String[] args) {
	ExecutorService pool = Executors.newFixedThreadPool(50);
	for(int i=0;i<50;i++){
		pool.execute(new Runnable() {
			@Override
			public void run() {
				while(true){
					Map<String, String> data = new HashMap<String, String>();
					data.put("q", "SELECT MAX(value) FROM sensor where device_code='d_bt_0' and sensor_code='s_btg_8' and time>=1485541192230000000 and time<=1485627592230000000");
					HttpRequest.post("http://10.77.110.226:8086/query?db=ruc_test1").form(data).code();
				}
			}
		});
	}
	try {
		pool.awaitTermination(Long.MAX_VALUE,TimeUnit.DAYS);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:21,代码来源:HttpRequestTest.java

示例2: doGet

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	
	String token = AuthConfig.getToken();
	Long user_id=AuthConfig.getUser_id();
	OutputStream os = resp.getOutputStream();
	
	if (token!=null&&user_id>0) {
		Map<String, String> data = new HashMap<String, String>();
		data.put("token", token);
		data.put("user_id", user_id.toString());
		
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
		
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:21,代码来源:GetAllTextsServlet.java

示例3: post

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
/**
 * 构造POST提交表单请求,返回响应结果
 * @param params
 * 提交的参数
 * @param address
 * 提交的地址
 * @param connectTimeout
 * @param readTimeout
 * @return
 */
public static HttpResult post(Map<String,String> params,String address,int connectTimeout,int readTimeout) throws IOException {
    HttpResult result = new HttpResult();
    if(params == null){
        params = new HashMap<>();
    }
    if(StringUtils.isEmpty(address)){
        log.error("请求地址不能为空");
        return null;
    }
    URL requestUrl = new URL(address);
    long start = System.currentTimeMillis();
    HttpRequest httpRequest = new HttpRequest(requestUrl,"POST")
            .connectTimeout(connectTimeout).readTimeout(readTimeout).trustAllCerts().trustAllHosts();
    httpRequest.form(params,"UTF-8");
    result.setStatus(httpRequest.code());
    result.setResult(httpRequest.body());
    result.setResponseTime(System.currentTimeMillis() - start);
    return result;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:30,代码来源:HttpUtil.java

示例4: insert

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
private Status insert(String data) {
	HttpRequest hr = null;
	long costTime = 0L;
	try {
		hr = HttpRequest.post(WRITE_URL).connectTimeout(100 * 1000).readTimeout(100 * 1000);
		long startTime = System.nanoTime();
		hr.send(data);
		hr.code();
		long endTime = System.nanoTime();
		costTime = endTime - startTime;
	} catch (Exception e) {
		e.printStackTrace();
		return Status.FAILED(-1);
	}
	System.out.println(hr.body());
	if (hr.code() >= 200 && hr.code() < 300) {
		return Status.OK(costTime);
	} else {
		return Status.FAILED(costTime);
	}
}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:22,代码来源:InfluxDB.java

示例5: getOpenIdByCode

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
/**
 * Warning: This function need to visit weixin websites
 *
 * @return
 */
public static String getOpenIdByCode(String code) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("appid", Const.WX_APP_ID);
    params.put("secret", Const.WX_APP_SECRET);
    params.put("code", code);
    params.put("grant_type", "authorization_code");
    String body = HttpRequest.get("https://api.weixin.qq.com/sns/oauth2/access_token", params, true).body();

    Map result = JSON.parseObject(body, Map.class);
    String openId = (String) result.get("openid");
    if (openId == null) {
        logger.error(body);
    }
    return openId;
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:21,代码来源:WeixinUtils.java

示例6: getAccessTokenByCode

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
/**
 * Warning: This function need to visit weixin websites
 *
 * @return
 */
public static Map getAccessTokenByCode(String code) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("appid", Const.WX_APP_ID);
    params.put("secret", Const.WX_APP_SECRET);
    params.put("code", code);
    params.put("grant_type", "authorization_code");
    String body = HttpRequest.get("https://api.weixin.qq.com/sns/oauth2/access_token", params, true).body();

    Map result = JSON.parseObject(body, Map.class);
    String access_token = (String) result.get("access_token");
    if (access_token == null) {
        logger.error(body);
    }
    return result;
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:21,代码来源:WeixinUtils.java

示例7: createIndex

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
public void createIndex(String indexName, String indexJson) {
    if (esHost == null) {
        log.warn("ES host not set as system property");
        return;
    }
    log.info("checking if the search index exists for name: " + indexName);
    int responseCode = HttpRequest.get("http://" + esHost + ":9200/" + indexName).code();
    if (responseCode != 404) {
        log.info("index already setup");
        return;
    }
    log.info("Creating search index with name: " + indexName);
    String response = HttpRequest.put("http://" + esHost
            + ":9200/" + indexName)
            .contentType("application/json").send(indexJson)
                    .body();
}
 
开发者ID:oneops,项目名称:oneops,代码行数:18,代码来源:SearchDal.java

示例8: main

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
		Map<String, String> data = new HashMap<String, String>();
		
		// 公钥加密过程
//		String plainText = "{\"username\":\"test\",\"password\":\"123456\"}";
//		byte[] cipherData = RSAEncrypt.encrypt(GlobalRSAKey.RSAPublicKey,
//				plainText.getBytes());
//		String cipher = Base64.encode(cipherData);
//		data.put("ciphertext", cipher);
//		String resultStr = HttpRequest.post("http://127.0.0.1:8080/auth.cgi")
//				.form(data).body();
//		
//		//解密前数据
//		System.out.println(resultStr);
		
		data.put("token","12d3s");
		data.put("user_id", "1");
		String resultStr =  HttpRequest.post("http://127.0.0.1:8080/token.cgi").form(data).body();
		
		//解密后的数据
		byte[] res = RSAEncrypt.decrypt(GlobalRSAKey.RSAPublicKey, Base64.decode(resultStr));
		String restr = new String(res);
		System.out.println(restr);
	}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:25,代码来源:SecurityMainTest.java

示例9: doPost

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String group_id=req.getParameter("group_id");
	String token = AuthConfig.getToken();
	Long userid=AuthConfig.getUser_id();
	
	OutputStream os = resp.getOutputStream();
	//OperationBean respBean = new OperationBean();
	
	
	if ( group_id!=null && userid!=null) {

			Map<String, String> data = new HashMap<String, String>();
			data.put("user_id", userid.toString());
			data.put("token", token);
			data.put("group_id", group_id);
			String returnAnswer = HttpRequest.post(authUrl).form(data).body();
			os.write(returnAnswer.getBytes("UTF-8"));
			// 返回给前端
	}
	os.flush();
	os.close();

}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:25,代码来源:DeteleGroupServlet.java

示例10: doGet

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	Long userid=AuthConfig.getUser_id();
	String token=AuthConfig.getToken();
	
	OutputStream os=resp.getOutputStream();
	
	if (userid!=null && token!=null) {
		Map<String, String> data = new HashMap<String, String>();
		data.put("user_id", userid.toString());
		data.put("token", token);
		String returnAnswer = HttpRequest.get(authUrl+"?user_id="+userid+"&token="+token).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	} else {
		OperationBean respBean = new OperationBean();
		respBean.setCode(100);
		respBean.setMsg("token出错或userid出错");
		respBean.setRedirect(null);
		os.write(JsonUtil.beanToJson(respBean).getBytes("UTF-8"));
	}
	os.flush();
	os.close();


}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:26,代码来源:GetAllGroupsServlet.java

示例11: doGet

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	Long userid = AuthConfig.getUser_id();
	String token = AuthConfig.getToken();
	OutputStream os = resp.getOutputStream();
	
	if (userid != null && token != null) {
		Map<String, String> data = new HashMap<String, String>();
		data.put("user_id", userid.toString());
		data.put("token", token);
		String returnAnswer = HttpRequest.get(authUrl+"?user_id="+userid+"&token="+token).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	} else {
		OperationBean respBean = new OperationBean();
		respBean.setCode(100);
		respBean.setMsg("token出错或userid出错");
		respBean.setRedirect(null);
		os.write(JsonUtil.beanToJson(respBean).getBytes("UTF-8"));
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:24,代码来源:GetGroupsServlet.java

示例12: doPost

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String group_id=req.getParameter("group_id");
	String user_id=req.getParameter("user_id");
	String token=AuthConfig.getToken();
	
	OutputStream os=resp.getOutputStream();
	if (group_id!=null&&user_id!=null&&token!=null) {
		Map<String, String> data=new HashMap<String,String>();
		
		data.put("group_id", group_id);
		data.put("user_id", user_id);
		data.put("token", token);
		
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:21,代码来源:DeteleTextGroupServlet.java

示例13: doPost

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String user_id_str = req.getParameter("user_id");
	String name = req.getParameter("name");
	String token=AuthConfig.getToken();
	
	OutputStream os = resp.getOutputStream();

	if (user_id_str!=null&&name!=null&&token!=null) {
		Map<String, String> data=new HashMap<String,String>();
		data.put("user_id", user_id_str);
		data.put("name", name);
		data.put("token", token);
		
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:21,代码来源:AddTextGroupServlet.java

示例14: doPost

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String name = req.getParameter("name");
	String group_id_str = req.getParameter("group_id");
	String token=AuthConfig.getToken();
	
	OutputStream os = resp.getOutputStream();
	
	if (name!=null&&group_id_str!=null&&token!=null) {
		Map<String, String> data=new HashMap<String,String>();
		data.put("name", name);
		data.put("groud_id", group_id_str);
		data.put("token", token);
		 
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	}
	os.flush();
	os.close();
	
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:22,代码来源:UpdateGroupNameSerlvet.java

示例15: doPost

import com.github.kevinsawicki.http.HttpRequest; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
		throws ServletException, IOException {
	
	String token = AuthConfig.getToken();
	String text_id=req.getParameter("text_id");
	OutputStream os = resp.getOutputStream();
	
	if (token!=null&&text_id!=null) {
		Map<String, String> data = new HashMap<String, String>();
		data.put("token", token);
		data.put("text_id", text_id);
		
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:20,代码来源:DeteleTextServlet.java


注:本文中的com.github.kevinsawicki.http.HttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。