NSURLSession请求put

NSURL *url = [NSURL URLWithString:@""];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"PUT";
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
request.allHTTPHeaderFields = @{@"uin":uin,@"ticket":ticket};
NSString *msg = @"a=1&b=2";
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = data;
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}] resume];

你可能感兴趣的:(NSURLSession请求put)