Hutool工具包HttpRequest.post(url)请求设置,Hutool使用HttpRequest.post(url)请求

如下


	JSONObject jsonObject = new JSONObject();
	jsonObject.put("clientId", clientId);
	jsonObject.put("secret", SecureUtil.md5(secret));
	jsonObject.put("userId", userId);
	
	Map<String, String > heads = new HashMap<>();
	heads.put("Content-Type", "application/json;charset=UTF-8");
	
	String result = HttpRequest.post(userRoleUrl)
		.headerMap(heads, false)
		.body(jsonObject.toJSONString()).timeout(30*1000).execute().body();
		


	JSONObject json = new JSONObject();
	json.put("code", config.getCode());
	json.put("pass", config.getPass());
	
	String result = HttpRequest.post(config.getUrlPersonal())
		.header("Content-Type", "application/x-www-form-urlencoded").form(json).execute().body();
		

官方例子:https://hutool.cn/docs/#/http/Http%E8%AF%B7%E6%B1%82-HttpRequest

你可能感兴趣的:(后端,后端封装效果,http,java)