@Test //post请求 附加lui就能够参数
public void postljcs( ) {
ResponseEntity<String> a=null;
String url="http://192.168.0.113:8080/api/xxta?data={1}";
try {
HttpHeaders hea= new HttpHeaders();
hea.setContentType(MediaType.APPLICATION_JSON_UTF8);
hea.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<String> fo= new HttpEntity<>(hea) ;
a=ss.postForEntity(url, fo, String.class,"data=1");
System.out.println(a);
}catch(Exception e) {
logger.error(e.toString());
}
}
@Test
public void post( ) {
ResponseEntity<String> a=null;
String token="XXX";
String url="http://192.168.0.113:8080/api/XXX=20201215&token=";
String json="json串";
try {
HttpHeaders hea= new HttpHeaders();
hea.setContentType(MediaType.APPLICATION_JSON_UTF8);
hea.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<String> fo= new HttpEntity<>(json,hea) ;
a=ss.postForEntity(url+token, fo, String.class);
System.out.println(a);
}catch(Exception e) {
logger.error(e.toString());
}
}
第一个是路径参数方式
第二个是json方式 两个都是post