android 文件上传(POST方式模拟表单提交)
直接上代码
/**
* @category 上传文件至Server的方法
* @param uploadUrl 上传路径参数
* @param uploadFilePath 文件路径
* @author ylbf_dev
*/
private void uploadFile(String uploadUrl,String uploadFilePath) {
String end = "\r\n";
String twoHyphens = "--";
String boundary = "******";
try {
URL url = new URL(uploadUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type"</