更新时间:2021-11-02 23:30:57
调整了代码,现在看来可以了.基本上将URL的末尾拆分为POST的正文.
Adjusted your code and this now seems to work. Basically split end of URL into the body of the 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);