iOS put请求

2018-07-02  本文已影响58人  一个萝卜X个坑
       //请求参数 URL
        NSString *RequestUrlString=[NSString stringWithFormat:@"%@%@?%@",[ShaoLin ShareMyInformation].serverIP,urlString,NSLstring];
        //把URL字符串进行编码,否则有中文或符号会出错
        RequestUrlString = [RequestUrlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        NSURL *url = [NSURL URLWithString:RequestUrlString];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        request.HTTPMethod = @"PUT";
        //此处为请求头,类型为字典
        [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        NSLog(@"请求URLput==%@",RequestUrlString);
        [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            [SVProgressHUD dismiss];
            if (error) { 
             //请求失败
                NSLog(@"put失败了error==      %@",error);
            } else { 
               //请求成功

                });
            }
            
        }] resume];
上一篇 下一篇

猜你喜欢

热点阅读