|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
How do I attach a file to the HTTP POST request? I am using URLConnection to sen
|
JavaFAQ Home » JSP, Servlets

Question: How do I attach a file to the
HTTP POST request? I am using URLConnection to send the HTTP request.
Answer: you need to write code like this.
Please find exact details yourself 
URL dest = "http://www.myurlhere.com ";
URLConnection urlCon = dest.openConnection();
// prepare input and output
urlCon.setDoInput(true);
urlCon.setDoOutput(true);
// Disable caching
urlCon.setUseCaches(false);
// Post output
DataOutputStream out =
new DataOutputStream(urlCon.getOutputStream());
out.writeBytes( file.toString );
out.flush();
out.close();
// return servlet response as a DataInputStream
DataInputStream in = new DataInputStream(urlCon.getInputStream());
// and so on
....
***************************************
Our older tips: March 22, 2001 - October 21, 2002
read here.
All published and not published on site tips you can find
here
Printer Friendly Page
Send to a Friend
..
Search here again if you need more info!
|
|
|