【问题标题】:Upload file in Android webview在 Android webview 中上传文件
【发布时间】:2013-10-24 09:38:46
【问题描述】:

我有一个这样的html表单

<form data-ajax="false" action='UserPhoto.php' class="settings" method='POST' enctype='multipart/form-data' >
<input type='file' style="height:25px" name='photo' />
<input type='hidden' name='task' value='upload'>
<input type='hidden' name='file_size' value='5000000'>

我想通过 webView posturl 功能上传,可以吗? 据我所知 posturl 可以通过这种方式发送字符串数据

String value1 = "persistent=1";
String value2 = "&email="+ 2nd_value;
String value3 = "&password="+ 3rd_value;
String postData = value1+value2+value3;
webView.postUrl("http://www.abc.php",EncodingUtils.getBytes(postData, "BASE64"));

但是我可以将 .png 与一些字符串值一起发布吗? 我知道另一种使用这种方式上传照片的方法

conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("photo", fileName); 

但这种方式不与 webview 通信,我需要使用 webview 发布照片,因为用户会话保持不变。

感谢您的帮助。

【问题讨论】:

    标签: php android webview image-uploading


    【解决方案1】:

    如果您仅使用 webview 将图像上传到服务器,您最好使用类似 http://loopj.com/android-async-http/ 的东西。它更简单、更快捷。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-28
      • 2012-06-12
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多