1
我想設置一個緩存,但是我使用的方法'as below'沒有被線程訪問。cachedResponseForRequest方法不被訪問
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
我正在初始化這樣的連接,並且connectionDidFinishLoading被訪問,所以我不知道我在想什麼。
- (IBAction)searchRequest:(NSData *)postBodyData
{
//Set database address
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"https://127.0.0.1:88"];
NSURL *url = [NSURL URLWithString:databaseURL];
NSString *postLength = [NSString stringWithFormat:@"%d", [postBodyData length]];
//SynchronousRequest to grab the data, also setting up the cachePolicy
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0]; //if request dose not finish happen within 60 second timeout.
// NSInputStream *fileStream = [NSInputStream inputStreamWithData:postBodyData];
[request setHTTPMethod: @"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/octet-stream" forHTTPHeaderField:@"content-type"];
[request setHTTPBody:postBodyData];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData data];
} else {
// Inform the user that the connection failed from the connection:didFailWithError method
}
}
任何幫助,將不勝感激。
oh man,這是一個真正的bugger ...我以爲我瘋了,因爲我之前使用過這個方法..只是沒有POST請求..感謝您的迴應。最後一個問題,關於這些第三方解決方案,我是否需要擔心在將來對它的支持,就像ASIHTTPRequest以及開發人員如何放棄該項目一樣。 – 2012-03-30 01:19:23
您總是需要爲任何事情擔心。你不得不擔心蘋果不贊成你使用的東西。如果這涉及到一個開源項目,您應該查看代碼並決定是否適合自己修復它。如果是這樣,那麼風險很小。 – 2012-03-30 12:55:32