You can connect to anything using sockets. In the end that's how it's
going to get done anyway... The trick is reading the correct RFC so you
know the proper syntax for what you pump down the stream and read from
the stream.
The RFC for HTTP 1.1 happens to be 2616 and you can find a copy here;
http://www.faqs.org/rfcs/rfc2616.html
HTH
> > I would like to be able to send HTTP requests without having to rely on
> > java.net.URL. Any ideas as to how I'd do this? I don't see any
[quoted text clipped - 7 lines]
>
> Arne
jvsoft.org@gmail.com - 15 Aug 2006 13:18 GMT
See Java socket tutorial
http://www.developerzone.biz/index.php?option=com_content&task=view&id=94&Itemid=36
yawnmoth - 21 Aug 2006 04:38 GMT
> You can connect to anything using sockets. In the end that's how it's
> going to get done anyway... The trick is reading the correct RFC so you
[quoted text clipped - 4 lines]
> http://www.faqs.org/rfcs/rfc2616.html
> <snip>
I'm familiar with HTTP/1.0 and 1.1. I'm just not sure how to *send*
data with java.net.Socket. Looking at its documentation, I see three
functions that have send in their name - getSentBufferSize (which
doesn't send anything), sendUrgentData (which sends one byte), and
setSendBufferSize (again, doesn't send anything). So how do I send
"GET / HTTP/1.0\r\nHost: www.google.com"? Do I send it one byte at a
time or can I send the whole string?
EJP - 21 Aug 2006 05:26 GMT
> I'm familiar with HTTP/1.0 and 1.1. I'm just not sure how to *send*
> data with java.net.Socket.
Socket.getOutputStream().write()
yawnmoth - 21 Aug 2006 15:30 GMT
> > I'm familiar with HTTP/1.0 and 1.1. I'm just not sure how to *send*
> > data with java.net.Socket.
>
> Socket.getOutputStream().write()
That doesn't seem to be working as I'd expect it to. Here's my
program.
import java.net.*;
import java.io.*;
public class Test
{
public static void main(String[] args)
{
try
{
Socket sock = new Socket("www.google.com", 80);
sock.getOutputStream().write("GET / HTTP/1.0\r\nHost:
www.google.com\r\n\r\n".getBytes());
BufferedReader text = new BufferedReader(new
InputStreamReader(sock.getInputStream()));
while ( text.ready() )
{
System.out.println(text.readLine());
}
}
catch (Exception e)
{
}
}
}
I don't get any output when running it, however.
Gordon Beaton - 21 Aug 2006 15:36 GMT
> I don't get any output when running it, however.
It may be necessary to flush the OutputStream.
It's almost certainly necessary to drop the call to ready().
Change your read loop to something like this:
while ((line = text.readLine()) != null) {
System.out.println(line);
}
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
yawnmoth - 21 Aug 2006 15:40 GMT
> > I don't get any output when running it, however.
>
[quoted text clipped - 7 lines]
> System.out.println(line);
> }
That worked - thanks!
And looking at my code... I see I should have been doing
e.printStackTrace as well... ah well...