Permalink
Browse files

Removing exception caused by multipartFormRequestWithMethod:path:para…

…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...
1 parent 635b809 commit eb20980e86f06a9e47d33ed7e9cf2979a0bd0f0c @mattt mattt committed Jan 18, 2012
Showing with 1 addition and 6 deletions.
  1. +1 −6 AFNetworking/AFHTTPClient.m
@@ -235,7 +235,7 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
[request setAllHTTPHeaderFields:self.defaultHeaders];
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)]];
[request setURL:url];
} else {
@@ -265,11 +265,6 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
parameters:(NSDictionary *)parameters
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];
__block AFMultipartFormData *formData = [[AFMultipartFormData alloc] initWithStringEncoding:self.stringEncoding];

0 comments on commit eb20980

Please sign in to comment.