我是 android 编码的新手,我环顾四周,试图找到解决问题的方法。我要发送数据的网站有一个表格。我想从编辑文本字段中的活动中收集数据并将其发送到 Web 表单并提交 Web 表单。
经过一些在线阅读后,我遇到了以下方法。有人能告诉我这是否正确吗?如果网络表单有一个名为“名称”的字段(我可以访问站点源)。并且用户输入“John Doe”,所以 NameValue 对将是“name”,“John Doe”,对吗?
HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),10000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(),10000);
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name1", "value1"));
nameValuePairs.add(new BasicNameValuePair("name2", "value2"));
nameValuePairs.add(new BasicNameValuePair("name3", "value3"));
// etc...
try{
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
}
catch(Exception e)
{
}