<p>My code is like the following:</p>

<pre><code>URLConnection cnx = address.openConnection();
cnx.setAllowUserInteraction(false);         
cnx.setDoOutput(true);
cnx.addRequestProperty("User-Agent", 
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
InputStream is = cnx.getInputStream();
</code></pre>

<p>Is it ok if I set the headers before I get the <code>InputStream</code>? Will my header be sent, or will the server see the default <code>URLConnection</code>'s user-agent ( if any ) ?</p>

The headers
must
be set prior to getting the
```
InputStream
```
to have any affect - an
```
IllegalStateException
```
will be thrown if the connection is already open.
As far as the
```
User-Agent
```
header specifically, it should be sent if it has been set.
See the
URLConnection
JavaDoc.