私はJavaで新しいです。ポストjsonデータをWebサーバーに送信したい My Volleyの投稿を以下に示します。ここでAndroid Volley jsonのデータをサーバーに転送
public void postData(String url,JSONObject data,final VolleyCallback mResultCallback){
RequestQueue requstQueue = Volley.newRequestQueue(mContext);
JsonObjectRequest jsonobj = new JsonObjectRequest(Request.Method.POST, url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if(mResultCallback != null){
mResultCallback.notifySuccess(response);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(mResultCallback != null){
mResultCallback.notifyError(error);
}
}
}
){
//here I want to post data to sever
};
requstQueue.add(jsonobj);
}
は私MainActivityコード
JSONObject data = null;
try {
String datas = "{'email': email,'password': password}";
data = new JSONObject(datas);
}catch (JSONException e){
e.printStackTrace();
}
String url = "http://example.com";
である私は私のPostDataのメソッドにJSONデータを投稿したいです。 このjsonデータをサーバーに投稿するにはどうすればよいですか?
'新しいJsonObjectRequest(Request.Method.POST、url、null、' JSONObject paramsの場合は3番目のパラメータ)。 nullをあなたのjsondataに置き換えてください –