I do not know how to add parameters to the post request to Overpass-API. To create request I am using AFNetworking.
1) at the beginning, i build query in overpass-turbo.eu than i export it to XML, so i get this
<osm-script>
<query type="node">
<has-kv k="amenity" v="drinking_water"/>
<bbox-query e="12.51119613647461" n="41.89248629819397" s="41.88659196260802" w="12.488558292388916"/>
</query>
<print/>
</osm-script>
and put that in NSString
NSString *myString = @"<osm-script><query type=\"node\"><has-kv k=\"amenity\" v=\"drinking_water\"/><bbox-query e=\"12.51119613647461\" n=\"41.89248629819397\" s=\"41.88659196260802\" w=\"12.488558292388916\"/></query><print/></osm-script>";
2) than i try build params AFNetworking - How can I PUT and POST raw data without using a key value pair?
So i create the NSData category method base64DataFromString is available here.
And create my request
NSString *urlString = @"http://overpass-api.de/api/interpreter";
NSURL *myUrl = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myUrl];
// Generate an NSData from your NSString (see below for link to more info)
NSData *postBody = [NSData base64DataFromString:myString];
// Add Content-Length header if your server needs it
unsigned long long postLength = postBody.length;
NSString *contentLength = [NSString stringWithFormat:@"%llu", postLength];
[request addValue:contentLength forHTTPHeaderField:@"Content-Length"];
// This should all look familiar...
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postBody];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response data: %@", responseObject);
self.textView.text = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
self.textView.text = [NSString stringWithFormat:@"%@",error];
}];
[manager.operationQueue addOperation:operation];
3) But now i get error
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo=0x1700fc680 {NSUnderlyingError=0x170247290 "Request failed: unacceptable content-type: text/html", com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x170230860> { URL: http://overpass-api.de/api/interpreter } { status code: 400, headers {
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 491;
"Content-Type" = "text/html; charset=utf-8";
Date = "Sat, 13 Dec 2014 13:25:37 GMT";
Server = "Apache/2.2.22 (Ubuntu)";
Vary = "Accept-Encoding";
} }, NSErrorFailingURLKey=http://overpass-api.de/api/interpreter, com.alamofire.serialization.response.error.data=<...
What im doing wrong?