Volley 没有通过参数?

Posted

技术标签:

【中文标题】Volley 没有通过参数?【英文标题】:Volley doesn't pass the params? 【发布时间】:2020-07-06 00:10:11 【问题描述】:

我想每次增加 +1 并将其添加到服务器 SQL 数据库。但问题是下面的代码只运行一次,其余的 +1 没有添加到服务器。我检查了很多答案,但没有一个对我有用,所以我问一下。那么有人能告诉我我在代码上犯了什么错误吗?实际上我是 volley 的新手,所以你的详细指南可以帮助我更好地学习。

我的代码 android Studio

 queue = Volley.newRequestQueue(this);

         request = new StringRequest(StringRequest.Method.GET, "http://alfaazshayaristatus.com/apps/alfaaz/upload.php?id=" + id, new Response.Listener<String>() 
            @Override
            public void onResponse(String response) 


                Toast.makeText(ImageViewActivity.this, response, Toast.LENGTH_SHORT).show();


            
        , new Response.ErrorListener() 
            @Override
            public void onErrorResponse(VolleyError error) 


                Toast.makeText(ImageViewActivity.this, ""+error.getMessage(), Toast.LENGTH_LONG).show();

            
        

        );

        queue.add(request);

我的PHP

<?php

include 'config.php';

$id = $_GET['id'];
$response = array();


     $insert = $db->query("UPDATE AlfaazStatus SET views=views+1 WHERE id=$id");
            if($insert)


                $message = "The file id ".$id." add +1 Like";


$success = true;

            else


$success = false;

                $message = "File upload failed, please try again.";
            




$response["success"] = $success;
$response["message"] = $message;

header('Content-Type:Application/json');

echo json_encode($response);
?>

【问题讨论】:

【参考方案1】:

您是否尝试使用此方法为图像添加调整大小?

Picasso.with(getActivity())
                        .load(imageUrl)
                        .placeholder(R.drawable.placeholder)
                        .error(R.drawable.error)
                        .resize(screenWidth, imageHeight)
                        .fit.centerCrop()
                        .into(imageView);

希望对你有帮助

【讨论】:

问题变了,亲爱的,但是,是的,我已将这种方法用于旧问题,并且对我有用。谢谢,但你能看看这个更新的问题

以上是关于Volley 没有通过参数?的主要内容,如果未能解决你的问题,请参考以下文章

删除带有标头和参数的请求 Volley

如何通过 Volley Android 发布多个大图像文件

如何通过带有标头的 volley 发布 JSON 请求?

Android Volley框架的使用

Volley - POST/GET 参数

带有参数的 Volley jsonObjectRequest 不起作用