Spring 提供 Android 下HTTP请求方法
http://projects.spring.io/spring-android/
api : http://docs.spring.io/spring-android/docs/1.0.2.BUILD-SNAPSHOT/api/
post
postForObject(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
uriVariables 指的是给url中缺省参数赋值
例如
RestTemplate restTemplate = new RestTemplate();
// Add the String message converter
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
String param ="";
if(url.contains("?")){
if(url.contains("=")){
param = "&dataStr={pt}{data}";
}else{
param = "dataStr={pt}{data}";
}
}else{
param = "?dataStr={pt}{data}";
}
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("data", data);
dataMap.put("pt", "123131313");
String result= restTemplate.postForObject(url + param, null, String.class,dataMap);
如果只有一个参数