以下是流网址,未在浏览器中显示任何结果。
如何从上面的网址获取数据并在xcode中显示在视图中?
我有以下用户代码:
NSURL *url = [NSURL URLWithString:@"http://streamerapi.finance.yahoo.com/streamer/1.0?s=MSFT,GOOG&k=l10,c10,p20,g00,h00&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *loginString = [NSString stringWithFormat:@"%@:%@", API_USERNAME, API_PASSWORD];
NSData *postData = [loginString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Data : %@",data);
但它会返回NULL
个结果。
请告诉我解决方案。