We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm experimenting a bit with using the API of the dutch railways. It's a open API and available from: http://www.ns.nl/api/api. Unfortunately everything is in dutch, but luckily that's irrelevant for my question.
I'm trying to get the data into processing. You can request the info via simple URL's. For instance:
it requires a login that needs your email and a key. Which you can include in the URL for automatic login. This an example which is working ( I made a dummy one on a email adress I use for testing etc)
login: ruben_vleuten@hotmail.com key: RghFLhdU_ot9g8tcVvlnjJa_zcToVTM0H1iHB-XchgprrgrZk3SJhA
When I use this URL in my browser it returns xml so it works properly. But the problems is when I try to import it in a processing sketch. When I do something like this it gives me an error.
XML testXml;
void setup() { testXml = loadXML("http://ruben_vleuten@hotmail.com:RghFLhdU_ot9g8tcVvlnjJa_zcToVTM0H1iHB-XchgprrgrZk3SJhA@webservices.ns.nl/ns-api-treinplanner?fromStation=Utrecht+Centraal&toStation=Wierden&departure=true");
println(testXml);
}
It seems to work with other URL's so don't really know what the problem is. I'm also not very experienced using API's so it might be a rookie mistake.
Hope someone can help.
Cheers,
Ruben.
Answers
(i've edited your post to stop the forum treating the url in the code as special)
Quick answer (lack of time): you can try and use the Client class (from the Network library) to access the data. One advantage is that it allows to specify some headers, like giving a fake User-Agent header. Some APIs try to do automatic detection of client, and might require some data to work properly.
There are several threads around similar issues.
I will come back to this issue later, to do more experiments.
The part with the login can be disturbing too. You should look how it is done in regular Java, perhaps.
OK, I had time tonight, and was successful in getting data from the site:
Hi PhiLho
This is great. Thank you so much. Will need some thing to figure out what is exactly happening. But seems like it's working. So thank you a lot, this is more than I asked for :).