im trying to build a little http client with java... right now i have 2 things that give me a headache... what im basically trying to do is to "download" the apache logo -- apache_pb.gif -- from my apache server, which i then want to store in a new GIF-file called "pic.gif"...
here is my code:
import java.io.*; import java.net.*;
class test { private Socket s; PrintWriter toServer;
public test() { try { byte[] b; int i;
File outputFile = new File("pic.gif"); FileOutputStream toFile = new FileOutputStream(outputFile);
s = new Socket ("127.0.0.1",80);
BufferedInputStream fromServer = new BufferedInputStream(s.getInputStream());
toServer = new PrintWriter(s.getOutputStream(), true); toServer.println("GET /apache_pb.gif HTTP/1.0 \n");
the problem now is, that when i cut off the server-header manually (with notepad), and then save the file to disk and try to open it with MSIE, MSIE will refuse to display it... and this although the original GIF-file (apache-pb.gif) seems to be 100% identical to the copy (pic.gif), when compared visually in notepad, and 100% identical in size when compared in ms explorer... furthermore, if i take a look at the properties of the GIF-file in MSIE, it will tell me that the file-size is -1 Byte and that it is not a GIF-file... obviously i am doing something wrong.... can anybody tell me what my problem is??
my 2nd problem is, is there a nice way how i can cut off the server header?
i would really appreciate it, if somebody could help me...