/**
* 上传文件 form post
*
* @category 各种类型,图片,文档等,统一视为file
* @param url
* @param request
* @param params
* @param filePath
* 必须
* @param fileName
* @param listner
* @param actionId
* @param otherFlag
* @param fileType
* 必须 1:头像;2:身份证;3:在职证明;4:资产证明;5:名片;
*/
public static void uploadFile(String uploadUrl, String request, Map<String, String> params,
String filePath, String fileName, int fileType, HttpConnectionHelperListener listner,
int actionId, int otherFlag) {
// form标准提交格式拼接
String end = "\r\n";
String twoHyphens = "--"; // 两个连字符
String boundary = "---------------pedataisfantasticforvcpe"; // 分界符的字符串随便
try {
URL url = new URL(uploadUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod("POST");
// 设置Http请求头
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Charset&#
Android HttpURLConnection模拟浏览器Form上传提交二进制文件
最新推荐文章于 2021-04-24 11:46:40 发布
该博客详细介绍了如何在Android中使用HttpURLConnection实现模拟浏览器Form提交,进行二进制文件上传。通过设置请求头和Content-Type,以multipart/form-data格式发送文件,同时传递其他参数。示例代码中包含了文件读取、流处理和错误处理的部分。
摘要由CSDN通过智能技术生成