Re: faking HTTP with a socket channel
On Mon, 11 Aug 2008 07:45:49 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :
When you get your HttpConnection object, just what has happened at
that point?
I did an experiment here in the output:
a: 4160
b: 4362600 <- . openConnection
c: 142284360 <- .connect
200
d: 229896880 <- .getResponseCode
e: 2611160 <-.getInputStream
So it looks like .connect does the work -- establishing the socket and
sending the header.
It looks like getResponse code blocks until the response from the
server.
elapsed( "a:" );
URLConnection urlc = source.openConnection();
elapsed( "b:" );
if ( urlc == null )
{
throw new IOException( "Unable to make a connection." );
}
else
{
if ( DEBUGGING )
{
// get simple name of class without the package
String s = urlc.getClass().getName();
// manually chop off all past the last dot.
int lastDot = s.lastIndexOf( '.' );
if ( lastDot >= 0 )
{
s = s.substring( lastDot + 1 );
}
System.out.println( " Connecting to " +
source.toString() + " with " + s );
}
}
urlc.setAllowUserInteraction( false );
urlc.setDoInput( true );
urlc.setDoOutput( false );
urlc.setUseCaches( false );
urlc.setReadTimeout( readTimeout );
urlc.setConnectTimeout( connectTimeout );
urlc.setRequestProperty( "Accept",
"text/html, image/png, image/jpeg,
image/gif, application/x-java-serialized-object, text/x-java-source,
text/xml, application/xml, "
+
"text/css,
application/x-java-jnlp-file, text/plain, application/zip,
application/octet-stream, *; q=.2, */*; q=.2" );
urlc.connect();
elapsed( "c:" );
System.out.println( ( (HttpURLConnection)
urlc).getResponseCode() );
elapsed("d:" );
long length = urlc.getContentLength();// -1 if not available
// O P E N _ S O U R C E, raw byte stream
InputStream is = urlc.getInputStream();
elapsed( "e:" );
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com