我刚刚开始使用 AFNetworking,但我似乎无法弄清楚如何让以下工作。
我的 URL 指向一个 PHP 文件,该文件已打印出从数据库中检索到的 JSON 数据,但使用 AFNetworking 我得到“预期内容类型”错误。
我的代码如下,但 URL 不同。
NSURL *url = [NSURL URLWithString:@"http://www.example.com/json.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
NSLog(@"JSON: %@", [json valueForKeyPath:@"results"]);
} failure:nil];
[operation start];