从 android 应用程序获取数据并将其上传到本地主机服务器
Get data from android app & Uploading it to localhost server
我是 android 应用程序开发的新手,我的任务是将数据上传到本地主机服务器,用户将(填写表格并按下提交按钮)upload.Tell 如果需要任何库.
提前致谢。
您使用的是 HTML 页面吗?如果是这样,它就像一个 normla html 页面,您有一个带有字段和提交按钮的表单。
相反,如果您有一个 UI 并想将数据上传到删除服务器,则有几个选项:
- 手动
- 使用一些库(OkHttp 或 Volley)
如果您想手动操作:
HttpURLConnection con = (HttpURLConnection) ( new URL(url)).openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write( ("name=" + name).getBytes());
InputStream is = con.getInputStream();
byte[] b = new byte[1024];
while ( is.read(b) != -1)
buffer.append(new String(b));
con.disconnect();
希望对您有所帮助!
如果你喜欢我在 my blog
中写了一篇关于它的 post
我是 android 应用程序开发的新手,我的任务是将数据上传到本地主机服务器,用户将(填写表格并按下提交按钮)upload.Tell 如果需要任何库.
提前致谢。
您使用的是 HTML 页面吗?如果是这样,它就像一个 normla html 页面,您有一个带有字段和提交按钮的表单。 相反,如果您有一个 UI 并想将数据上传到删除服务器,则有几个选项:
- 手动
- 使用一些库(OkHttp 或 Volley)
如果您想手动操作:
HttpURLConnection con = (HttpURLConnection) ( new URL(url)).openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write( ("name=" + name).getBytes());
InputStream is = con.getInputStream();
byte[] b = new byte[1024];
while ( is.read(b) != -1)
buffer.append(new String(b));
con.disconnect();
希望对您有所帮助! 如果你喜欢我在 my blog
中写了一篇关于它的 post