400 bad request when to send request - Piwik Java Tracking API

I’m developing an app which I plan on implementing Piwik Analytics into. Although there seems to be no real documentation (unless I’m blind) on how to use the Java Tracking API, I think I managed to figure it out, but when I try it, I get this error

WARNING: Warning:400 Bad Request
org.piwik.PiwikException: error:400 Bad Request
	at org.piwik.SimplePiwikTracker.sendRequest(SimplePiwikTracker.java:878)
	at net.aman207.test.Main.main(Main.java:32)

Here is my code

SimplePiwikTracker tracker = new SimplePiwikTracker("http://aman207.net/piwik/piwik.php");
tracker.setPageCustomVariable("test", "10");

//This is line 32

I also tried this

String datURL = tracker.getLinkTrackURL("http://aman207.net/piwik/piwik.php").toString();
URL url = new URL(datURL);			
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

but this just prints out response code 404 which doesn’t make any sense because if I paste the link into my browser it works perfectly and logs correctly (I have debug mode on).

What am I doing wrong? Thanks!

Answer here: https://forum.matomo.org/t/400-bad-request-get/18515/2