Permalink
Browse files

Allow user to pass custom cookies

  • Loading branch information...
1 parent 2bc361d commit 344d5dac35a4d860ab0057df45db2670aa96e063 @ascorbic ascorbic committed Jan 20, 2011
Showing with 10 additions and 4 deletions.
  1. +10 −4 iPhone/FileUploader/FileUploader.m
@@ -102,16 +102,22 @@ - (void) uploadFile:(NSURL*)file toServer:(NSString*)server withParams:(NSMutabl
if(!fileKey) {
fileKey = @"file";
}
-
- NSString *boundary = @"*****com.beetight.formBoundary";
-
NSURL *url = [NSURL URLWithString:server];
-
+
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
+ if([params objectForKey:@"__cookie"]) {
+ [req setValue:[params objectForKey:@"__cookie"] forHTTPHeaderField:@"Cookie"];
+ [params removeObjectForKey:@"__cookie"];
+ [req setHTTPShouldHandleCookies:NO];
+ }
+
+ NSString *boundary = @"*****com.beetight.formBoundary";
+
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[req setValue:contentType forHTTPHeaderField:@"Content-type"];
+ [req setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
NSString* userAgent = [[webView request] valueForHTTPHeaderField:@"User-agent"];
if(userAgent) {
[req setValue: userAgent forHTTPHeaderField:@"User-agent"];

0 comments on commit 344d5da

Please sign in to comment.