Pregunta

As the title states, I'm attempting to simply send a HTTP request to a webserver with URLConnection, but when I attempt to run the script, it does not send the request, nor does it give me an error.

Code:

public static URLConnection connection;
new URL("http://website.com/dostuff.php?whatever=" + whatever).openConnection();
¿Fue útil?

Solución

URL.openConnection does not create the connection immediately. It only connects after you call a method that requires a connection. For example:

URL url = ...;
InputStream in = url.openStream(); // connection happens here
// you can now read the output from in
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top