Posted By:
Omair_Ashfaq
Posted On:
Monday, June 11, 2001 05:36 PM
I have a MimeMultiPart object with two MimeBodyParts and I want to POST this MimeMultiPart object to an HTTPS address. One body part is an xml document and the other is a regular text file. Can somebody tell me how to do this? My code looks something like this: System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); URL url = new URL("https://www.sun.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty(&qu
More>>
I have a MimeMultiPart object with two MimeBodyParts and I want to POST this MimeMultiPart object to an HTTPS address. One body part is an xml document and the other is a regular text file. Can somebody tell me how to do this?
My code looks something like this:
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
URL url = new URL("https://www.sun.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("content-type", "multipart/mixed");
MimeMultipart mimeMultipart = new MimeMultipart();
MimeBodyPart xmlPart = new MimeBodyPart();
xmlPart.setHeader("Content-Type", "text/xml; charset=UTF-8");
xmlPart.setHeader("Content-ID", "
<12345678>");
xmlPart.setContent("
<?xml version="1.0" encoding="UTF-8"?>
somevalue
");
mimeMultipart.addBodyPart(xmlPart);
MimeBodyPart attachmentPart = new MimeBodyPart();
File file = new File("file.txt");
FileDataSource fds = new FileDataSource(file);
DataHandler dh = new DataHandler(fds);
attachmentPart.setFileName("file.out");
attachmentPart.setHeader("Content-Type", "text/plain; charset=US-ASCII");
attachmentPart.setHeader("Content-ID", "98765432");
attachmentPart.setDisposition(Part.ATTACHMENT);
attachmentPart.setDataHandler(dh);
mimeMultipart.addBodyPart(attachmentPart);
mimeMultipart.writeTo(conn.getOutputStream());
<<Less