我想將一些數據發佈到一個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