Android URL Download connectForMultipart(String url)

Here you can find the source of connectForMultipart(String url)

Description

connect For Multipart

Declaration

public static OutputStream connectForMultipart(String url)
            throws Exception 

Method Source Code

//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";
    }
}

Related

  1. downloadJson(URI uri)
  2. getURLString(String urlStr)
  3. getBytesFromUrl(String url)
  4. getWebContent(String pvUrl)
  5. sendPOST(final String myurl, final String paramns)