美文网首页
iOS put请求

iOS put请求

作者: 一个萝卜X个坑 | 来源:发表于2018-07-02 17:26 被阅读58次
           //请求参数 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];
    

    相关文章

      网友评论

          本文标题:iOS put请求

          本文链接:https://www.haomeiwen.com/subject/smbluftx.html