JAVA示例
public void javaDemo(){
String apiUrl = api接口url;
Gson gson = new Gson();
HttpClient client = null;
PostMethod method = null;
try{
client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method = new PostMethod(apiUrl);
//传参
String paras = "{CompID:1, SecretKey:e10adc3949ba59abbe56e057f20f883e, RequestId:12345678901234567890}";
RequestEntity entity = new StringRequestEntity(paras,"application/json","UTF-8");
method.setRequestEntity(entity);
method.addRequestHeader("Content-Type","applicrgbation/json;charset=utf-8");
int code = client.executeMethod(method);
if(code!=HttpStatus.SC_OK){
throw new Exception("");
}
String respText = method.getResponseBodyAsString();
//返回的数据
Map<String, Object> map = gson.fromJson(respText, Map.class);
for(String key : map.keySet()){
System.out.println(key+"值:"+map.get(key));
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(method!=null){
method.releaseConnection();
}
if(client!=null){
client.getHttpConnectionManager().closeIdleConnections(1);
}
}
}