Hi,
I seem to have an unexplained problem trying to access data from api.transport.nsw.gov.au using Java.
I can issue an HTTP Get using POSTMAN to this endpoint (I’m seeking vehicle positions (busses)), and this is successfull. I get the payload. But in Java - I get an HTTP 401 error.
YES - I am putting in the same apikey :). and the same URL.
What am I missing ? Below is my small JAVA program:
package GTFSSample;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class Parse {
public static void main(String args) throws Exception {
// From URL
URL url = new URL(“https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/buses”);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setRequestMethod(“GET”);
con.setRequestProperty(“Authorization”, “apikey ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ”);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream());
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
thanks - Steve