2011-11-28 45 views
1

當前我試圖通過URLConnection和URlRequest讀取本地服務器中的文件。它似乎按照原樣工作,直到我再次執行請求時文件中的更改沒有任何效果。下面是我如何建立請求的代碼:Urlconnection IOS 5

-(void)openURLConnectionWithString:(NSString *)urlString{ 
    NSTimeInterval timeout= 120; 
    self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:timeout]; 
    self.urlConnection = [NSURLConnection connectionWithRequest:request delegate:self]; 
    if(urlConnection){ 
     NSLog(@"Connecting..."); 
     self.receivedData = [NSMutableData data]; 
    }else{ 
     NSLog(@"Connection failed!"); 
    } 
} 

這就是我如何利用包含上述功能的類:

AsyncScheduleParser *getSchedule = [[AsyncScheduleParser alloc] init]; 
getSchedule.delegate = self; 
[getSchedule openURLConnectionWithString:@"http://localhost/scheduleC.txt"]; 
[getSchedule release]; 

只有我改名字了一旦我再次閱讀文件,就會顯示更改。

回答

0

請求完成後不要忘記清理所有相關對象(如self.receivedData)。最好的解決方案是簡單地爲每個正在執行的請求創建一個新對象,並在完成後釋放該對象。

+0

奇怪的是...即使在我重新啓動Apache並重新啓動模擬器後,沒有任何更改,一旦我提出了要求我的意思是如果我重新啓動應用程序,一切都應該清潔我是嗎?...順便說一句我有另一個對象,執行GDataXML的另一個請求,它工作順利......兩個請求都以相同的方式構建。 – user1070019