Here you can find the source of connectForMultipart(String url)
public static OutputStream connectForMultipart(String url) throws Exception
//package com.java2s; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static OutputStream connectForMultipart(String url) throws Exception { HttpURLConnection con = (HttpURLConnection) (new URL(url)) .openConnection();//from www. ja va2s.c o m con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + getBoundry()); con.connect(); OutputStream os = con.getOutputStream(); return os; } public static String getBoundry() { return "SwA" + Long.toString(System.currentTimeMillis()) + "SwA"; } }