2
我把NSMutableURLRequest
請求dispatch_async
,但它不工作。然而,NSURLRequest
的作品。代碼:NSMutableURLRequest和NSURLConnection無法在GCD dispatch_async中工作?
dispatch_queue_t queue1 = dispatch_get_global_queue(0, 0);
dispatch_async(queue1, ^{
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
[request setHTTPMethod:@"GET"];
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];//It doesn't work!
//***
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
NSURLResponse* theResponse = nil;
NSError* theError = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:&theResponse
error:&theError];
//This works great!
});
有NSMutableURLRequest
和NSURLRequest
之間有什麼區別?或者,我以錯誤的方式使用NSURLConnection
?
謝謝!