Link to home
Start Free TrialLog in
Avatar of aomega
aomega

asked on

Quesion about HTTP Get Request

I am having some difficulty sending an http get request to the server through a socket connection, downloading binary data located in a relative folder on the server and then writing it to a local file.

sock = new Socket(server, port);
in = new DataInputStream(sock.getInputStream());
out = new DataOutputStream(sock.getOutputStream());

String request = "GET /folder/folder/datafile HTTP 1.0\r\n\r\n";
//then i send the get request to the server
out.writeBytes(request);

The problem is that I when i go to read the response from the socket into a byte array and write the bytearray to the file; the data either is not written at all (filesize is 0) or in some cases the data is partially written.  Is there something I am doing wrong with the get request?  Any comments would be appreciated.  Thanks
ASKER CERTIFIED SOLUTION
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of int_20h
int_20h

You can use a library that deals with HTTP.  This one is very good!
http://www.innovation.ch/java/HTTPClient/