使用ASIFormDataRequest將文件上傳到服務器時非常奇怪(對我而言)問題。ASIHTTPRequest:上傳數據/服務器時(可能)特定於運營商的問題,收到空白POST
通過WiFi上傳時,沒有問題,我可以上傳就好。使用O2 UK作爲運營商通過3G上傳時,也沒有問題。當我使用完全相同的代碼上傳使用Vodafone UK的相同服務器時,HTTP請求會到達服務器並剝去POST內容。如果我嘗試了同樣的請求,但沒有上傳圖片(只需將test => yes添加爲某些POST數據),那麼這將起作用,但是如果我有test => yes並附加了一個文件,它會通過POST到達服務器數據被剝離。
NB我在iPhone 4S上使用最新版本的ASIHTTPRequest,並且可以在其他幾款使用Vodafone UK和O2 UK的手機上進行重現。
所以,我指着我的objc代碼在下面的PHP腳本,它只是打印出什麼它收到:
<?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.');
我使用的objc代碼:
- (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]);
}
如果我運行的WiFi應用程序啓用,或者在英國O2,我得到如下回應:
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.
到目前爲止好!
如果我試了WiFi禁用,但對英國沃達豐公司幾乎全部的3G信號:
Success Response: FILES: Array
(
)
POST: Array
(
)
GET: Array
(
)
done.
非常奇怪:不僅是現在,該文件丟失,但「測試」 POST值也失蹤。但是,PHP或ASIHTTPRequest都沒有錯誤。
任何人都可以爲我擺脫任何光線嗎?如果沃達豐正在操縱這樣的東西,爲什麼它不被人們熟知?我唯一能找到的其他人報告類似的問題posted a year ago。
如果我註釋掉[請求addData]行,然後它完美的作品:
Success Response: FILES: Array
(
)
POST: Array
(
[Test] => Yes
)
GET: Array
(
)
done.
很奇怪。我一直試圖讓這個工作整天,但沒有運氣到目前爲止。如果有人能夠擺脫任何光線,或者甚至出現同樣的問題,我將非常感激。
哦,夥計。下面是使用HTTPS當響應: '成功響應:FILES:數組 ( [照片] =>數組 ( [名稱] => smalltestimage.png [型] =>圖像/ PNG [tmp_name的值] =>的/ tmp/phpzzo5xF [錯誤] => 0 [尺寸] => 13211 ) ) POST:數組 ( [測試] =>是 ) GET:數組 ( ) 完成。 ' 所以這是通過HTTPS工作,並且我猜想它有某種相關性。很奇怪!!沃達豐是否有這樣做的理由? –
沒有線索。這聽起來好像是一個他們已經設置好的HTTP代理。希望有所幫助! –
Upvote。乾杯:) –