I'm trying to use Java to use the Restful API at https://www.routexl.nl to get optimised travelling routes for some locations. At the moment I'm just using the example stuff on website but my lack of knowledge in Rest HTTP stuff is really holding me back. I had opted to use JavaLite but saw UniRest. Happy to use these or other Rest/HTTP clients.
Ideally I'm looking for some code which will send off an array of objects that have lat/longs and description information and return a sorted list of these objects using the shortest driving route but happy to get the code below working, which uses the example from the website.
This is why I've got so far:-
//import com.mashape.unirest.http.HttpResponse;
//import com.mashape.unirest.http.JsonNode;
//import com.mashape.unirest.http.Unirest;
//import com.mashape.unirest.http.exceptions.UnirestException;
import org.javalite.http.Get;
import org.javalite.http.Http;
import org.javalite.http.Post;
public class RestClient {
public static void main(String[] args) {
Post post = Http.post("https://api.routexl.nl/tour", "locations=[{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.05429\",\"lng\":\"4.248618\"},{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.076892\",\"lng\":\"4.26975\"},{\"address\":\"Uden, The Netherlands\",\"lat\":\"51.669946\",\"lng\":\"5.61852\"},{\"address\":\"Sint-Oedenrode, The Netherlands\",\"lat\":\"51.589548\",\"lng\":\"5.432482\"}]")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.basic("USERNAME", "PASSWORD");
System.out.println(post.text());
System.out.println(post.responseMessage());
}
}
And this is the output I get:-
No input found:
Conflict
EDIT:- Got it working by removing the two headers. Anyone have any idea why that would be? EDIT2:- That makes sense RouteXL. OK here is another go which seems to work.
Post post2 = Http.post("https://api.routexl.nl/tour")
.param("locations","[{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.05429\",\"lng\":\"4.248618\"},{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.076892\",\"lng\":\"4.26975\"},{\"address\":\"Uden, The Netherlands\",\"lat\":\"51.669946\",\"lng\":\"5.61852\"},{\"address\":\"Sint-Oedenrode, The Netherlands\",\"lat\":\"51.589548\",\"lng\":\"5.432482\"}]")
.basic("USERNAME", "PASSWORD");
System.out.println(post2.text());
System.out.println(post2.responseMessage());