Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bug that form data request can't add custom Content-Type to header

  • Loading branch information...
commit 8109273e839052ecb9944e4c2a0e22fd1eb7937f 1 parent 3ed0b3c
@OpenFibers authored
Showing with 22 additions and 3 deletions.
  1. +22 −3 Classes/ASIFormDataRequest.m
View
25 Classes/ASIFormDataRequest.m
@@ -213,6 +213,19 @@ - (void)buildPostBody
#endif
}
+- (BOOL)isHeaderContainsContentType
+{
+ BOOL headerContainsContentType = NO;
+ for (id key in self.requestHeaders.allKeys)
+ {
+ if ([key isKindOfClass:[NSString class]] && [key isEqualToString:@"Content-Type"])
+ {
+ headerContainsContentType = YES;
+ break;
+ }
+ }
+ return headerContainsContentType;
+}
- (void)buildMultipartFormDataPostBody
{
@@ -228,8 +241,11 @@ - (void)buildMultipartFormDataPostBody
CFRelease(uuid);
NSString *stringBoundary = [NSString stringWithFormat:@"0xKhTmLbOuNdArY-%@",uuidString];
- [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, stringBoundary]];
-
+ if (![self isHeaderContainsContentType])
+ {
+ [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, stringBoundary]];
+ }
+
[self appendPostString:[NSString stringWithFormat:@"--%@\r\n",stringBoundary]];
// Adds post data
@@ -288,7 +304,10 @@ - (void)buildURLEncodedPostBody
NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding([self stringEncoding]));
- [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@",charset]];
+ if (![self isHeaderContainsContentType])
+ {
+ [self addRequestHeader:@"Content-Type" value:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@",charset]];
+ }
NSUInteger i=0;
Please sign in to comment.
Something went wrong with that request. Please try again.