详见:知乎,get和post到底有什么区别
区别:
GET参数在URL中(query string)
POST参数在body中、url也能带参数(query string)
REST中,
安全:GET、POST都不安全,因为HTTP本身是明文协议
主动发请求:
CloseableHttpClient client = null;
CloseableHttpResponse httpResponse = null;
String url = "https://api.weibo.com/oauth2/access_token";
client = HttpClients.createDefault();
// 创建http请求
HttpPost httpPost = new HttpPost(url);
Map<String, Object> map = new HashMap();
map.put("client_id", appKey);
map.put("client_secret", appSecret);
map.put("redirect_uri",redirect_uri);
map.put("grant_type", "authorization_code");
map.put("code", code);
httpPost.setEntity(new UrlEncodedFormEntity(createParam(map), Consts.UTF_8));
httpResponse = client.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity, "UTF-8");
JSONObject resultObj = JSONObject.parseObject(result);
String token = resultObj.getString("access_token");
String expire = resultObj.getString("remind_in");
String weiboAccount = resultObj.getString("uid");