DELETE 请求参数保存在Body 中

NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
 
    NSString * url = [NSString stringWithFormat:signatureProxy,model2.scheduleId];
    NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    req.HTTPMethod = @"DELETE";
    req.HTTPBody = [NSJSONSerialization dataWithJSONObject:parameter options:NSJSONWritingPrettyPrinted error:nil];//[parameter JSONData];//dic字典相当于parameters,请求体里的东西
    req.allHTTPHeaderFields = @{
                                @"Content-Type":@"application/json"
                                };//请求头里的东西
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:req queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if (connectionError) {
            //失败
            [ToolOfClass showMessage:@"操作失败"];
        } else {
            //成功
            dispatch_async(dispatch_get_main_queue(), ^{
                //回调或者说是通知主线程刷新,
                [_tableView reloadData];
                [ToolOfClass showMessage:@"操作成功"];
           });
        }
    }];

转载于:https://www.cnblogs.com/frounk/p/6769114.html

比如我们有一个名为UserService的服务,它提供了一些RESTful API,我们想通过Feign来调用这些API。我们可以先定义一个接口,如下所示: ```java @FeignClient(name = "user-service") public interface UserFeignClient { @RequestMapping(method = RequestMethod.GET, value = "/users/{userId}") User getUser(@PathVariable("userId") String userId); @RequestMapping(method = RequestMethod.POST, value = "/users") User createUser(@RequestBody User user); @RequestMapping(method = RequestMethod.PUT, value = "/users/{userId}") User updateUser(@PathVariable("userId") String userId, @RequestBody User user); @RequestMapping(method = RequestMethod.DELETE, value = "/users/{userId}") void deleteUser(@PathVariable("userId") String userId); } ``` 上述代码,@FeignClient注解指定了服务名为"user-service",Feign会根据这个服务名来发起HTTP请求。接口的每个方法都对应一个HTTP请求,通过@RequestMapping注解指定请求的方法、路径、参数等信息。 接口定义好之后,我们就可以在代码直接注入这个接口,并调用它的方法来发起HTTP请求,如下所示: ```java @RestController public class UserController { @Autowired private UserFeignClient userFeignClient; @GetMapping("/users/{userId}") public User getUser(@PathVariable String userId) { return userFeignClient.getUser(userId); } @PostMapping("/users") public User createUser(@RequestBody User user) { return userFeignClient.createUser(user); } @PutMapping("/users/{userId}") public User updateUser(@PathVariable String userId, @RequestBody User user) { return userFeignClient.updateUser(userId, user); } @DeleteMapping("/users/{userId}") public void deleteUser(@PathVariable String userId) { userFeignClient.deleteUser(userId); } } ``` 上述代码,我们注入了UserFeignClient接口,并在方法直接调用它的方法来发起HTTP请求。Feign会自动将接口定义的参数和返回值转换成对应的HTTP请求和响应。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值