AFNetworking を使用して山のリストを取得する次の iOS コードがあります。失敗ブロックに「Bad URL」エラーが表示されます。
- (void) loadMountains
{
NSString * loadMountainQueries = @"select * where { ?Mountain a dbpedia-owl:Mountain; dbpedia-owl:abstract ?abstract. FILTER(langMatches(lang(?abstract),"EN")) } ";
NSString * urlString = [NSString stringWithFormat:@"http://dbpedia.org/sparql/?query=%@",loadMountainQueries];
NSLog(@"%@", urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[AFHTTPRequestOperation addAcceptableContentTypes:
[NSSet setWithObjects:@"application/json", @"sparql-results+json", @"text/json", @"text/html", @"text/xml", nil]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Response %@", [operation responseString]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Response %@", [operation responseString]);
NSLog(@"Error: %@", error);
}];
[operation start];
}
URLを自動的にエンコードすると仮定AFHTTPRequestOperation
しますが、念のために言っておきますが、エンコードされた URL を使用すると、同じ応答「Bad URL」が返されます。Safari で機能する同じクエリが、Objective C では機能しません。
私は何を間違っていますか?