私のアプリと私のPHPスクリプトの間の接続を処理するGoogle Volley APIを使ってアンドロイドアプリを作成しています。 何らかの理由で、アプリは私のサーバーにデータを送信しません。Androidのボレーのポストリクエストが機能しない
私のgetParams()
メソッドは正しく呼び出されますが、印刷しようとするとnullが返されます。すべては実際にそのデータが私のPHPスクリプトがnullである変数
public class Server_interaction
{
String server_url = "http://xxxxxx/update_location.php"; //hidden from you ;)
String response_string;
RequestQueue queue;
Context context;
public Server_interaction(Context context)
{
this.context = context;
queue = Server_singleton.getInstance(context).getRequestQueue();
}
public static final String TAG = Server_interaction.class.getSimpleName();
public void post_request(final VolleyCallback callback)
{
StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
response_string = response;
callback.onSuccess(response_string);
//requestQueue.stop();
Log.i(TAG, "the response is: "+ response_string);
}
}
, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error){
response_string = "Something went wrong";
//error.printstacktrace()
//requestQueue.stop();
Log.i(TAG, "something went wrong. Is the server up and running?");
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
String the_name = "olaf";
String the_mail = "lalalal";
String the_country = "Norway";
String the_latitude = "33";
String the_longitude = "99";
Map<String, String> params = new HashMap<String, String>();
params.put("name", the_name);
params.put("email", the_mail);
params.put("country", the_country);
params.put("latitude", String.valueOf(the_latitude));
params.put("longitude", String.valueOf(the_longitude));
Log.i(TAG, "inside getparams : "+ super.getParams());
return super.getParams();
}
};//stringrequest parameter end
//add request to requestqueue
Server_singleton.getInstance(context).addToRequestQueue(stringRequest);
Log.i(TAG, "the response again:: "+ response_string);
}
}
元の質問でのgetParamsのような重要な情報を入れてください。これがなければ、リクエストキューが実行されていない、つまりstart()を呼び出すことができなかったように思えます。 –
私はシングルトンクラスを呼び出し、私はそのすべてのcorrectyが完了したと信じています。しかし、私のPHPサーバー側のスクリプトは空(null)の値を取得し、getparams.putメソッドは防ぐ必要がありますか?彼らはしないべきですか? – p3ob2lem
アイデアガベ? – p3ob2lem