Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将参数从android传递到php时出现问题_Php_Android_Android Volley - Fatal编程技术网

将参数从android传递到php时出现问题

将参数从android传递到php时出现问题,php,android,android-volley,Php,Android,Android Volley,我的android应用程序在使用截取发送参数时出现问题,我必须显示登录到我的应用程序的用户的数据,数据在服务器中,在我的php中,我用Json返回数据,当我在php中使用参数发送时,它工作得非常好,但在截取中,getParams不发送值​​我的全局变量 附加代码: java这里我读了Json public class MainLista extends AppCompatActivity { TextView txt1; ListView listaPerfil; Ar

我的android应用程序在使用截取发送参数时出现问题,我必须显示登录到我的应用程序的用户的数据,数据在服务器中,在我的php中,我用Json返回数据,当我在php中使用参数发送时,它工作得非常好,但在截取中,getParams不发送值​​我的全局变量

附加代码:

java这里我读了Json

public class MainLista extends AppCompatActivity {

    TextView txt1;
    ListView listaPerfil;
    ArrayAdapter adapter;
    HttpURLConnection con;

    String LINK = "phpurl";
    String url = LINK + "?email=" + Globales.USER_EMAIL + "?pass=" + Globales.USER_PASS;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_lista);
        listaPerfil = findViewById(R.id.listaPerfil);

        txt1 = findViewById(R.id.txt1);

        txt1.setText("email: " + Globales.USER_EMAIL + "\nPASS: " + Globales.USER_PASS);

        StringRequest sr = new StringRequest(Request.Method.POST, url, response -> { }, error -> {

            Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();

        }) {
            @Override
            protected Map<String, String> getParams() {

                Map<String, String> params = new Hashtable<>();
                params.put("email", Globales.USER_EMAIL);
                params.put("contrasena", Globales.USER_PASS);

                Log.d("IMPRESION", Globales.USER_EMAIL);
                Log.d("IMPRESION", Globales.USER_PASS);

                return params;
            }
        };

        RequestQueue rq = Volley.newRequestQueue(this);
        rq.add(sr);

        try {
            ConnectivityManager connMgr =(ConnectivityManager)
                    getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

            if (networkInfo != null && networkInfo.isConnected()) {

                new JsonTask().execute(new URL("phpurl"));

            } else {

                Toast.makeText(this, "ERROR DE CONEXION", Toast.LENGTH_LONG).show();

            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    private class JsonTask extends AsyncTask<URL, Void, List<Datos>> {

        @Override
        protected List<Datos> doInBackground(URL... urls) {
            List<Datos> datos = null;

            try {
                con = (HttpURLConnection)urls[0].openConnection();
                con.setConnectTimeout(15000);
                con.setReadTimeout(10000);

                int statusCode = con.getResponseCode();

                if (statusCode != 200) {
                    datos = new ArrayList<>();
                    datos.add(new Datos("error", null, null, null, null, null, null));
                } else {
                    InputStream in = new BufferedInputStream(con.getInputStream());

                    JsonParser parser = new JsonParser();

                    datos = parser.leerFlujoJson(in);
                }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                con.disconnect();
            }
            return datos;
        }

        @Override
        protected void onPostExecute(List<Datos> datos) {
            if (datos != null) {
                adapter = new AdaptadorDatos(MainLista.this, datos);
                listaPerfil.setAdapter(adapter);

            } else {
                Toast.makeText(getBaseContext(), "ERROR DE PARSING JSON", Toast.LENGTH_LONG).show();
            }
        }
    }
}

在PHP代码中,您使用GET方法,而在截击中,您使用POST方法。因此,为了实现这一点,您有2个选择将您的PHP更改为:

<?
    session_start();
    include('Conexion2.php');



    $email  = $_POST['email'];
    $pass   = $_POST['contrasena'];

    $sql="SELECT c.nombre, c.apellido, c.telefono1, c.email, c.fechanacimiento, c.contrasena, f.imagen
            FROM clientes AS c
            INNER JOIN fotos AS f ON c.clienteid = f.clienteid
            WHERE c.email = '$email' AND c.contrasena = '$pass'";

$pdo = pdo();
$query = $pdo -> prepare($sql);
$query -> execute(array($cons));
$res = $query -> fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($res);

echo $json;
    
?>
此外,您还需要更改指向以下内容的链接:

 StringRequest sr = new StringRequest(Request.Method.GET, url, response -> { }, error -> {

        Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();

    
    });
    
}
 String LINK = "https://viavel.com.mx/pruebas/PHPRicardo/ejemplomostrar.php"; 
 String url = LINK + "?email=" + Globales.USER_EMAIL + "&pass=" +Globales.USER_PASS;

对于GET方法中的多个值,必须在值之间添加“&”。Toast向您显示错误消息?@ShayKin hi,是的,目前刚刚获得“错误解析Json”,我没有意识到,现在您获得了“错误解析Json”?事实上,是的,但我猜问题在于AsyncTask和我的DataAdapter。我给您一个建议。我看到你发送电子邮件和密码,在这种情况下,最安全的方法是使用POST方法。使用Get方法在链接上共享密码是不切实际的
 StringRequest sr = new StringRequest(Request.Method.GET, url, response -> { }, error -> {

        Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();

    
    });
    
}
 String LINK = "https://viavel.com.mx/pruebas/PHPRicardo/ejemplomostrar.php"; 
 String url = LINK + "?email=" + Globales.USER_EMAIL + "&pass=" +Globales.USER_PASS;