从我的Android应用程序打开一个网站,发布值

时间:2012-05-16 16:36:01

标签: android android-intent

我需要从我的Android手机上访问一个网站,这个网站接受一些POST值。

当我在计算机上执行相同操作时,是一个带有php的表单:

<form name="form1" method="post" action="scripts/pago.php">

我可以使用以下代码打开网站:

        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
        startActivity(browserIntent);

它可以毫无问题地打开浏览器,但是,如何添加帖子值?

提前谢谢。

2 个答案:

答案 0 :(得分:1)

试试这个:

public void postData() throws Exception {


 HttpClient client = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://www.xyz.com");

 List<NameValuePair> list = new ArrayList<NameValuePair>(1);

 list.add(new BasicNameValuePair("name","ABC");

 httppost.setEntity(new UrlEncodedFormEntity(list));

 HttpResponse r = client.execute(httppost);

}

答案 1 :(得分:1)

Android Webview POST

您可以使用网页视图打开网页,然后发布帖子请求。在上面给出的链接上解释。