我一直在使用 NSURLConnection 的 sendAsynchronousRequest:queue:completionHandler: 方法。但是,我无法得到回应。每次 httpResponse 返回 nil。
NSString *str=@" http://maps.googleapis.com/maps/api/directions/json?origin=Bapunagar,%20Ahmedabad,%20Gujarat&destination=CG%20Road,%20Sattar%20Taluka%20Society,%20Usman%20Pura,%20Ahmedabad,%20Gujarat&sensor=false&units=metric&mode=transit&departure_time=1343605500&language=ar";
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL * url = [NSURL URLWithString:str];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[NSURLConnection
sendAsynchronousRequest:request
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error)
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"%@",httpResponse);
if ([data length] >0 && error == nil && [httpResponse statusCode] == 200)
{
NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",json);
}}];
这有什么问题?请帮忙