Java 如何将编辑文本字段文本上载到服务器
我想通过http连接在android中上传图像和编辑文本字段,图像正在上传,精细编辑文本字段未上传。请帮助我Java 如何将编辑文本字段文本上载到服务器,java,android,Java,Android,我想通过http连接在android中上传图像和编辑文本字段,图像正在上传,精细编辑文本字段未上传。请帮助我 FileInputStream fileInputStream = new FileInputStream(sourceFile); URL url = new URL(upLoadServerUri); // Open a HTTP connection to the URL conn =
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);
若我并没有错的话,你们想把图片和文本都上传到服务器上。 如果是,请参考下面的答案。 希望这有助于:
我认为这与否非常相似。我的功能是上传编辑文本字段和图像,如注册表……请帮助我。