oOOMIAO 2013-05-27 01:45 采纳率: 10%
浏览 1712

AFNetworking SPARQL查询失败

在IOS中使用AFNetworking 获取是山名的列表,运行之后报出:"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];
}

假设AFHTTPRequestOperation自动编码一个URL。但是使用了自动生成的URL之后还是报出URL错误。

在safari中运行可以,在objective-c中就不行了。

  • 写回答

1条回答

  • 码界一棵葱 2016-08-19 02:45
    关注

    请问你的问题解决了么,我碰到和你一样的问题!

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料