I have the next part of code:
dCon = (HttpURLConnection) new URL(torrentFileDownloadLink).openConnection();
dCon.setRequestProperty("Cookie", "uid=" + cookies.get("uid") + ";pass=" + cookies.get("pass"));
dCon.setRequestMethod("GET");
dCon.setConnectTimeout(30000);
dCon.setDoOutput(true);
But Wireshark shows that request method is “POST”. What am I doing wrong or this is just a bug? Btw, getRequestMethod say that method is “GET” but in reality it’s POST.
Setting the
URLConnection#setDoOutput()totruemeans that you’re about to write request data to the request body byURLConnection#getOutputStream(). This is impossible in combination with GET (which expects the request parameters in the request URL), thus the request method will implicitly be set to POST.If you don’t need to write any data to the request body, then just remove that line. It defaults to
false(and thus GET) anyway.See also:
URLConnectionto fire and handle HTTP requests?