Quantcast
Channel: What exactly does URLConnection.setDoOutput() affect? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by SoloPilot for What exactly does URLConnection.setDoOutput() affect?

$
0
0

Adding a comment, if you have a long lasting connection and you send both GETs and POSTs, this is what I do:

if (doGet) {    // some boolean
    con.setDoOutput(false); // reset any previous setting, if con is long lasting
    con.setRequestMethod("GET");
}
else {
    con.setDoOutput(true);  // reset any previous setting, if con is long lasting
    con.setRequestMethod("POST");
}

And to avoid making the connection long lasting, close it each time.

if (doClose)    // some boolean
    con.setRequestProperty("Connection", "close");

con.connect();              // force connect request

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>