Я поставил 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
неправильно?
Спасибо!