POSTing a file to a web page and reading response



Hi.

I'm trying to read raw data from disk, POSTING it to a site that
converts the file to another format, and then read and save the
response.

I have only found on the web information on how to post a string, not
binary data.
My code only writes the html page to file, not the response file.


This is my code so far:
----------------------
URL site = new URL("http://xxx.xxx.xxx.xxx";);


URLConnection conn = site.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty
("Content-Type", "multipart/form-data");
DataOutputStream dos;

OutputStream os = conn.getOutputStream();
dos = new DataOutputStream(os);
FileInputStream fis = new FileInputStream("c:\\temp\
\test.xxx");


int data;
while ((data = fis.read()) != -1) {
dos.write(data);

}
dos.flush();
DataInputStream in = new
DataInputStream(conn.getInputStream());
FileOutputStream fo = new FileOutputStream("c:\\temp\
\test.yyy");
while ((data = in.read()) != -1) {
fo.write(data);
}
fo.flush();
fo.close();
dos.close();
-----------------------

.



Relevant Pages

  • Re: POSTing a file to a web page and reading response
    ... binary data. ... server and read back the server's response. ... HttpURLConnection conn = ... DataOutputStream dos; ...
    (comp.lang.java.programmer)
  • Re: Back to school
    ... ill mannered posting to which I am responding. ... albeit not always the response that I was looking for. ... Ligon to a specific Ligon family in England. ... Jeremy Clarke line--but at one time they had a member in on the ...
    (soc.genealogy.medieval)
  • Re: Well, they went and did it.
    ... Foolishness like covering one's ass may be the norm where you work, but UseNet discussion forums are so dissimilar that one can hardly conceive of anything *less* alike. ... Most of what I do online, aside from reading a few emails each day, is reading and posting to UseNet newsgroups, where plain text is not only the norm but required. ... of my post far below my response, ...
    (alt.smokers.pipes)
  • Re: More musings about the state of this group
    ... denegration of this newsgroup since my so-called departure generated ... Gosh, just look at those posting tallies for the past four months, ... Your response is the ultimate in hypocrisy. ...
    (rec.music.beatles)
  • Re: More musings about the state of this group
    ... denegration of this newsgroup since my so-called departure generated ... Gosh, just look at those posting tallies for the past four months, ... Your response is the ultimate in hypocrisy. ...
    (rec.music.beatles)