-4

有人可以提供一个将简单数据发送到 PHP 服务器的 android 代码示例吗?我只需要从在 android 设备上创建的表单中发送几个 string、double 和 int 变量,将这些条目转换为 pdf 文档,然后将其发送回 android。如果我能得到一个至少将它发送到服务器的样本,那将有很大帮助。谢谢。

4

1 回答 1

1
public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "12345"));
        nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
} 
于 2012-06-06T19:50:19.387 回答