【问题标题】:How to get values from android on PHP server如何在 PHP 服务器上从 android 获取值
【发布时间】:2014-03-16 13:38:15
【问题描述】:
public void postData() {  
        // Create a new HttpClient and Post Header  
        HttpClient httpclient = new DefaultHttpClient();  
        HttpPost httppost = new HttpPost("http://localhost/howdy/welcome.php");  

        try {  

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
            nameValuePairs.add(new BasicNameValuePair("name", "rxn"));  
            nameValuePairs.add(new BasicNameValuePair("id", "b15803"));  
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

            // Execute HTTP Post Request  
            HttpResponse response = httpclient.execute(httppost);  
            int status = response.getStatusLine().getStatusCode();  
            System.out.println("data posted, status = " + status);  

        } catch (ClientProtocolException e) {  
            // TODO Auto-generated catch block  
        } catch (IOException e) {  
            // TODO Auto-generated catch block  
        } 





    }

这是我将姓名和 ID 发布到本地服务器的代码。现在接受这些参数的 php 代码将是什么,以便我能够存储在变量中并在网页上回显。 提前致谢

【问题讨论】:

    标签: java php android http httpclient


    【解决方案1】:

    您将此数据作为POST 请求发送,因此在另一端只需使用$_POST 变量获取它。这就是一个例子:

    $name = $_POST['name'];
    $id = $_POST['id'];
    
    echo "Hi, my name is $name and my id is $id\n";
    

    【讨论】:

      猜你喜欢
      • 2016-07-13
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2012-05-03
      • 2016-07-22
      相关资源
      最近更新 更多