Android - 将数据从Android应用程序发送到服务器上的PHP脚本

时间:2016-03-23 13:10:08

标签: php android

在我的应用中点击按钮时,我正在执行此操作:

poststatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                test++;
                status = status1.getText().toString();
                image = "http://www.thelalit.com/d/the-lalit-new-delhi/media/TheLalitNewDelhi/FoodBeverage_Restaurants/24_7Restaurant/24-7RestaurantDelhi.jpg";
                final HttpClient httpclient = new DefaultHttpClient();
                final HttpPost httppost = new HttpPost("http://ramsproject.16mb.com/jsonfinder.php");
                Thread thread = new Thread(new Runnable() {
                    @Override
                    public void run() {

                        try {
                            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                            nameValuePairs.add(new BasicNameValuePair("status", status));
                            nameValuePairs.add(new BasicNameValuePair("image", image));
                            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                            httpclient.execute(httppost);

                        } catch (Exception e) {

                            e.printStackTrace();
                        }
                    }
                });

我需要使用字符串的值&#34; status&#34;和&#34;图像&#34;在上面的函数中存储在服务器中的php脚本中。 php脚本如下:

<?php
$s=urldecode($_POST["status"]);
$url=urldecode($_POST["image"]);
$inp = file_get_contents('tjson1.json');
$extpos=strrpos($inp,']');
$thumb=substr($inp,0,$extpos).',';
$thumb=$thumb."\n".'{';
$thumb=$thumb."\n".'"id": "3",'."\n".'"name": "Ram",'."\n".'"image":'.'"'.$image.'"'.','."\n".'"status": '.'"'.$status.'"'.','."\n".'"profilePic": "https://pawnhero.ph/fb/images/default-dp.jpg",'."\n".'"timeStamp": "1403375851930",'."\n".'"url": null';
$thumb=$thumb."\n".'}'."\n".']'."\n".'}';
file_put_contents('tjson.json',$thumb);
?>

在这个php中,我无法访问变量s和url。它们在这个脚本中似乎是空的。我该怎么做才能解决它?

0 个答案:

没有答案