我嘗試用命令以檢索某些URL數據:NSURLConnection的失敗 - 1003
-(NSMutableData *) callUrl: (NSString *)url withData:(NSMutableDictionary *)data delegate:(id) delegate {
NSURL *executeUrl = [NSURL URLWithString:<string>];
NSURLRequest *request = [NSURLRequest requestWithURL: executeUrl
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
NSMutableData *receivedData = nil;
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:delegate];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
} else {
@throw @"Connection error";
}
return receivedData;
}
在委託(包括後connectionDidFinish和connectionDidFailWithError)我做的:
//some uninvasive alerts
// release the connection, and the data object
[connection release];
[receivedData release];
問題是,當我提供壞網址我得到了適當的錯誤 - 這是很好的一部分 - 但是我想執行第二個網址 - 很好,我有1003錯誤 - NSURLErrorCannotFindHost。
大約1-2分鐘後,我成功地調用URL並獲取數據。 我懷疑有些超時和端口業務,但在NSURLRequest中更改超時並不會改變事情。
UPDATE
事實證明 - 管理員必須通過WiFi網絡達到DNS服務器的一些問題。代碼很好。感謝您的迴應。 如果有一些類似的問題:嘗試IP地址而不是主機名。
你是怎麼修復它的?你嘗試使用IP地址嗎?我也面臨同樣的問題。請建議。 –