Permalink
Browse files

Added support for specifying content type when posting data in SyncRe…

…sponseFetcher
  • Loading branch information...
1 parent f5018e2 commit 47f8452b38f0f7b1215789a12a08aa5b22809ca5 @darrylhthomas darrylhthomas committed May 18, 2011
Showing with 12 additions and 1 deletion.
  1. +2 −0 SyncResponseFetcher.h
  2. +10 −1 SyncResponseFetcher.m
View
2 SyncResponseFetcher.h
@@ -30,6 +30,7 @@
NSMutableData *receivedData;
NSData *dataToSend;
+ NSString *dataToSendContentType;
NSURLConnection *urlConnection;
NSURL *requestURL;
NSDictionary *headers;
@@ -45,6 +46,7 @@
- (id)initWithURL:(NSURL*)aURL bodyStringAsUTF8B64:(NSString*)stringToEncode delegate:(id)aDelegate;
- (id)initWithURL:(NSURL*)aURL POSTData:(NSData*)POSTData delegate:(id)aDelegate;
+- (id)initWithURL:(NSURL*)aURL POSTData:(NSData*)POSTData contentType:(NSString*)contentType delegate:(id)aDelegate;
- (void)setRepresentedObject:(id)anObject;
- (id)representedObject;
- (NSInvocation*)successInvocation;
View
11 SyncResponseFetcher.m
@@ -49,12 +49,16 @@ - (id)initWithURL:(NSURL*)aURL bodyStringAsUTF8B64:(NSString*)stringToEncode del
}
- (id)initWithURL:(NSURL*)aURL POSTData:(NSData*)POSTData delegate:(id)aDelegate {
-
+ return [self initWithURL:aURL POSTData:POSTData contentType:nil delegate:aDelegate];
+}
+
+- (id)initWithURL:(NSURL*)aURL POSTData:(NSData*)POSTData contentType:(NSString*)contentType delegate:(id)aDelegate {
if ([self init]) {
receivedData = [[NSMutableData alloc] init];
requestURL = [aURL retain];
delegate = aDelegate;
dataToSend = [POSTData retain];
+ dataToSendContentType = [contentType copy];
}
return self;
}
@@ -93,6 +97,10 @@ - (BOOL)start {
//if POSTData is nil, do a plain GET request
if (dataToSend) {
+ if (dataToSendContentType) {
+ [request addValue:dataToSendContentType forHTTPHeaderField:@"Content-Type"];
+ }
+
[request setHTTPBody:dataToSend];
[request setHTTPMethod:@"POST"];
}
@@ -136,6 +144,7 @@ - (void)cancel {
- (void)dealloc {
[dataToSend release];
+ [dataToSendContentType release];
[requestURL release];
[receivedData release];
[urlConnection release];

0 comments on commit 47f8452

Please sign in to comment.