如何将编辑文本字段文本上传到服务器

时间:2014-01-22 12:52:28

标签: java android

我想通过使用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);

1 个答案:

答案 0 :(得分:0)

如果我没错,你想将图像和文本上传到服务器。 如果是这样,请参阅以下答案。 希望这可以帮助: https://stackoverflow.com/a/11590652/2623853