gpt4 book ai didi

ios - Overpass API - URL 获取,不适用于 iPhone,适用于 mac

转载 作者:行者123 更新时间:2023-11-28 21:50:43 25 4
gpt4 key购买 nike

我上次在我的项目中进行一些编码时遇到了这个问题,我似乎无法找到错误的位置。当我在我的 Mac 上的浏览​​器中尝试 URL 时,一切正常 - 我得到了显示的 json 文件。

我的代码如下:

    NSURL *url = [NSURL URLWithString:@"http://www.overpass-api.de/api/interpreter?data=[out:json];(way(around:150,49.4873181,8.4710548)[\"maxspeed\"];);out body;>;out skel;"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:25];

[request setHTTPMethod: @"POST"];

NSError *requestError;
NSURLResponse *urlResponse = nil;


NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
NSLog(@"%@", response1);
NSLog(@"%@", requestError);

NSString *myString = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding];
NSLog(@"myString: %@", myString);

我得到的错误如下:

Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x1706753c0 {NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x17044f480 "unsupported URL"}

最好的,雅各布

最佳答案

调整了您的代码,现在似乎可以正常工作了。基本上将 URL 的结尾拆分到 POST 的正文中。

    // Split URL from Body
NSURL *url = [NSURL URLWithString:@"http://www.overpass-api.de/api/interpreter"];
NSString *body=@"?data=[out:json];(way(around:150,49.4873181,8.4710548)[\"maxspeed\"];);out body;>;out skel;";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:25];

// Add body to the request
[request setHTTPMethod: @"POST"];
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];

NSError *requestError;
NSURLResponse *urlResponse = nil;


NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
NSLog(@"%@", response1);
NSLog(@"%@", requestError);

NSString *myString = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding];
NSLog(@"myString: %@", myString);

关于ios - Overpass API - URL 获取,不适用于 iPhone,适用于 mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28443446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com