【发布时间】:2014-01-22 12:52:28
【问题描述】:
我想通过http连接在android中上传图像和编辑文本字段,图像正在上传精细编辑文本字段没有上传。请帮助我。
FileInputStream fileInputStream = new FileInputStream(sourceFile);
URL url = new URL(upLoadServerUri);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
/* conn.setRequestProperty("uploaded_img", fileName);
conn.setRequestProperty("email", etemail.getText().toString());
conn.setRequestProperty("phone", etphone.getText().toString());
conn.setRequestProperty("message", etmessage.getText().toString());
conn.setRequestProperty("name",etname.getText().toString());
*/
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_img\";filename=\""
+ fileName + "\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"email\""+ lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(email);
dos.writeBytes(lineEnd);
【问题讨论】:
-
不,我的功能是上传编辑文本字段和图像,如注册表单...请帮助我。