W3C home > Mailing lists > Public > www-talk@w3.org > January to February 1998

Re: POSTing with a Socket

From: Jacob W. Anderson <jwa@zen.praja.com>
Date: Thu, 12 Feb 1998 18:23:43 -0800
Message-ID: <000801bd3826$676f44e0$1100000a@nog.praja.com>
To: <chris@surewould.com>, <www-talk@w3.org>
>        URL url = new URL(urlName);
>        Socket webSock = new Socket(url.getHost(), 80);

If you're using a proxy, this strategy will fail.  You can get the
output stream for the URL by calling URL.openConnection() and casting
the URLConnection class to an HttpURLConnection.  From HttpURLConnection
you can get the output stream, which you can convert to a DataOutputStream
and voila'!

>        out.println("POST " + url.getFile() + " HTTP/1.0");

>        out.println("Connection: Keep-Alive");
> ...

You need "\r\n" (CRLF) as the terminator for each header line.  When
you're done with the headers, just before the content, you need to send a 
blank line CRLF:

POST this/url/thingie HTTP/1.1\r\n
Connection: Keep-Alive\r\n
Content-Type: application/octet-stream\r\n
Content-Length: 500\r\n
\r\n
500 bytes of data

That's all it takes.  Since you are specifying Keep-Alive, you need to 
request HTTP/1.1 as your protocol, otherwise you can't do keep-alive and
the server will cut off the connection when it generates a response.

--Jacob W. Anderson (jwa@praja.com)
Received on Thursday, 12 February 1998 21:24:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 27 October 2010 18:14:23 GMT