Very strange (to me) problem when uploading files to a server using ASIFormDataRequest.
When uploading over WiFi, there's no problem, I can upload just fine. When uploading over 3G using O2 UK as the carrier, there's no problem either. When I upload using the exact same code the same server using Vodafone UK, the HTTP request arrives at the server with the POST content stripped out. If I try the same request but without uploading an image (just add test=>yes as some POST data), then this will work, but if I have test=>yes and attach a file, it arrives at the server with the POST data stripped out.
NB I'm using the latest version of ASIHTTPRequest on an iPhone 4S, and it's reproducible on several other phones using Vodafone UK and O2 UK variously.
So, I'm pointing my objc code at the following PHP script, which just prints out what it's received:
<?php
error_reporting(E_ALL);
ini_set("display_startup_errors","1");
ini_set("display_errors","1");
echo "FILES: ".print_r($_FILES,true);
echo "POST: ".print_r($_POST,true);
echo "GET: ".print_r($_GET,true);
die('done.');
The obj-c code I'm using is:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString: @"http://myserver.com/debugger.php"];
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(networkRequestSuccess:)];
[request setDidFailSelector:@selector(networkRequestFailure:)];
[request setTimeOutSeconds:120];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"smalltestimage" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
[request addPostValue:@"Yes" forKey:@"Test"];
[request addData:myData withFileName:@"smalltestimage.png" andContentType:@"image/png" forKey:@"photos"];
[request startSynchronous];
}
else{
NSLog(@"File not found..");
}
[request autorelease];
}
- (void)networkRequestSuccess:(ASIHTTPRequest *)request{
NSLog(@"Success Response: %@", [request responseString]);
}
- (void)networkRequestFailure:(ASIHTTPRequest *)request{
NSLog(@"Fail Response: %@", [request responseString]);
}
If I run the app with WiFi enabled, or on O2 UK, I get the following response:
Success Response: FILES: Array
(
[photos] => Array
(
[name] => smalltestimage.png
[type] => image/png
[tmp_name] => /tmp/phpYTdw4g
[error] => 0
[size] => 13211
)
)
POST: Array
(
[Test] => Yes
)
GET: Array
(
)
done.
So far so good!
If I retry with WiFi disabled, but with near-full 3G signal on Vodafone UK:
Success Response: FILES: Array
(
)
POST: Array
(
)
GET: Array
(
)
done.
Very odd: not only is the file now missing, but the 'test' POST value is also missing. However, no errors from either PHP or ASIHTTPRequest.
Can anyone shed any light for me? If Vodafone are manipulating stuff like this, why is it not more well known? The only other person I can find reporting a similar problem posted a year ago.
If I comment out the [request addData] line, then it works perfectly:
Success Response: FILES: Array
(
)
POST: Array
(
[Test] => Yes
)
GET: Array
(
)
done.
Very strange. I've been trying to get this working all day but no luck so far. I'd be very grateful if anyone could shed any light, or even is just having the same issue.