【发布时间】:2013-12-10 04:12:34
【问题描述】:
目前,我从 android 应用程序向我的 servlet 发送用户名作为参数。现在我想从 android 应用程序向我的 servlet 发送文本文件。这可能吗? 这是我尝试通过 Http 发送用户名的示例代码。
try
{
URL url = new URL("http:/xx.xxx.xxx.x/sample?user=admin"); // File as parameter
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String x = "";
String total = "";
int i=0;
ArrayList<String> content = new ArrayList();
while((x = r.readLine()) != null)
{
content.add(x);
}
in.close();
r.close();
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
以上代码工作正常,如何将存储在我的 SD 卡中的文本文件作为参数传递给 servlet?提前谢谢。
【问题讨论】:
-
是的,我们可以将文件发送到服务器,请参考以下链接reecon.wordpress.com/2010/04/25/…
-
代替图片放置你的文本文件
标签: java android http servlets