DELETE 请求参数保存在Body 中

微笑、不失礼 提交于 2020-03-16 04:08:25

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:@"操作成功"];
           });
        }
    }];

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!