我想将一些数据发布到一个URL,然后从该URL获取发布的数据并将其存储在数据库中。我试图回应发布的参数,但它们似乎没有发布,也没有显示任何错误。 下面是我用做后期功能:使用Android Volley向URL发布数据不起作用
public void insertDataWithVolley() {
String url = "http://apps.example.com/application/index.php/main/getParamsFromVolley";
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), response,
Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(),
Toast.LENGTH_LONG).show();
}
}) {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> mapObject = new HashMap<>();
mapObject.put("id", "ID");
Log.d("TAG", "Put id");
mapObject.put("name", "NAME");
Log.d("TAG", "Put name");
return mapObject;
}
};
requestQueue.add(stringRequest);
}
在PHP端,这是功能,见下图:
public function getParamsFromVolley() {
$id = null;
$name = null;
if (isset($_GET['id'])) {
$id= $this->input->get('id');
}
if (isset($_GET['name'])) {
$name= $this->input->get('name');
}
//store $pesapal_tracking_id in your database against the order with orderid = $reference09
echo 'name>>>>' . $id;
echo 'email>>>>' . $name;
//return $pesapal_tracking_id;
}
请协助
你的网址看起来有点怀疑 - (http://apps.example.com/application/index.php/main/getParamsFromVolley) – Tasos
嗨,我可以访问除了获取网址的其他东西。我编辑了这个问题,以包含我打电话的服务器端功能。 – Kabs
这将有助于您发布URL – Sharj