Pergunta

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();
Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top