我有一個NSMutableArray包含10個URL,我需要從中獲取HTTP標頭。一個接一個調用NSURLConnection
下面是我的代碼:
for(int i=0; i<[contactsArray count];i++)
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *reqstr=[NSString stringWithFormat:@"%@",urlString ];
[request setURL:[NSURL URLWithString:reqstr]];
NSLog(@"requested url is %@",reqstr);
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
[request setHTTPBody:[mDict JSONData]];
NSURLConnection *theConnection=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
}
當前結果:所有請求在一個時間去服務器。
預期結果:希望發送一個請求後得到響應切斷我想在後臺發送另一個請求。
有什麼建議嗎?
等待響應在發送下一個請求之前到達。 –
爲什麼不使用[AFNetworking](https://github.com/AFNetworking/AFNetworking) –