In your ASP.NET
page, you're reading the file and filename from the form that was posted.
In your Android code, you're adding the file and filename to the form and your ASP.NET
page is able to read it, so, no issues.
But, in your objective c code, you're adding the file and filename to the header of your request, so the ASP.NET
file, trying to read them from the form throws the exception, since it's trying to read the form variables that are null
.
Just try adding the file and filename to the form instead of the header in your Objective C
code and all will work out.
NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"arrow-next"]);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:@"http://aamc.kleward.com/OfflineCourse/iphone_Upload.aspx"]
cachePolicy:NSURLCacheStorageNotAllowed
timeoutInterval:120.0f];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"filename=%@&file=%@",@"myimage.png",[data base64Encoding]] ;
data = [postString dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[data length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
NSLog(@"response--%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
} else{
NSLog(@"error--%@",connectionError);
}
}];