• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

交换方法提供统一的方法模板进行四种请求:发布、上传、删除、获取

1、POST请求

string reqJsonStr=' { \ ' code \ ' : \ ' test code \ ',\'group\':\'testGroup\ ',\'content\':\'testContent\ ',\ ' order \ ' :1 }

http headers headers=new http headers();标题。设置内容类型(媒体类型.APPLICATION _ JSON);

HttpEntityString entity=new HttpEntityString(reqJsonStr,headers);

responseeentitymap resp=rest模板。exchange(DIC _ DATA _ URL,HttpMethod .帖子,实体,地图。类);

2、PUT请求

string reqJsonStr=' { \ ' id \ ' :227,\'code\':\'updateCC\ ',\'group\':\'UPDATE\ ',\'content\':\'updateCT\ ',\ ' order \ ' :9 }

http headers headers=new http headers();

标题。设置内容类型(媒体类型.APPLICATION _ JSON);

HttpEntityString entity=new HttpEntityString(reqJsonStr,headers);

responseeentitymap resp=rest模板。exchange(DIC _ DATA _ URL,HttpMethod .放,实体,地图。类);

3、DELETE请求

responseeentitymap resp=rest模板。exchange(DIC _ DATA _ URL '?id={id} ',HttpMethod .DELETE,null,Map.class,227);

4、GET请求

response entitystring结果=rest模板。exchange(URL,HttpMethod .GET,null,String.class,params);

说明:1)url:请求地址;

2)方法:请求类型(如:POST、PUT、DELETE、GET);

3)请求实体:请求实体,封装请求头,请求内容

4)响应类型:响应类型,根据服务接口的返回类型决定

5)uriVariables: url中参数变量值

Link to comment
Share on other sites