Skip to content

Commit

Permalink
Removing exception caused by multipartFormRequestWithMethod:path:para…
Browse files Browse the repository at this point in the history
…meters:constructingBodyWithBlock: is called with certain HTTP methods. Although message bodies for methods like HEAD, GET, and DELETE are traditionally ignored, there is nothing in the HTTP or multipart specs that explicitly forbid the use of multipart for a particular HTTP method.
  • Loading branch information
mattt committed Jan 18, 2012
1 parent 635b809 commit eb20980
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -235,7 +235,7 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
[request setAllHTTPHeaderFields:self.defaultHeaders]; [request setAllHTTPHeaderFields:self.defaultHeaders];


if (parameters) { if (parameters) {
if ([method isEqualToString:@"GET"]) { if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"] || [method isEqualToString:@"DELETE"]) {
url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]]; url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]];
[request setURL:url]; [request setURL:url];
} else { } else {
Expand Down Expand Up @@ -265,11 +265,6 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
parameters:(NSDictionary *)parameters parameters:(NSDictionary *)parameters
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData>formData))block constructingBodyWithBlock:(void (^)(id <AFMultipartFormData>formData))block
{ {
if (!([method isEqualToString:@"POST"] || [method isEqualToString:@"PUT"] || [method isEqualToString:@"DELETE"])) {
[NSException raise:@"Invalid HTTP Method" format:@"%@ is not supported for multipart form requests; must be either POST, PUT, or DELETE", method];
return nil;
}

NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil]; NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
__block AFMultipartFormData *formData = [[AFMultipartFormData alloc] initWithStringEncoding:self.stringEncoding]; __block AFMultipartFormData *formData = [[AFMultipartFormData alloc] initWithStringEncoding:self.stringEncoding];


Expand Down

0 comments on commit eb20980

Please sign in to comment.