我試圖將Jsonobject request
發送到服務器和我收到的volley timeouterror
發送的JSONObject服務器
我讀凌空RetryPolicy
東西的答覆,我應該增加我的請求的時間限制,直到獲得同樣的錯誤。請大家幫忙查看我的代碼,並協助我提供正確的請求。
在此先感謝
private void getpay() {
prgDialog.show();
final String amount = Fund_amount;
final String number = Card.getText().toString().trim();
final String year = Year.getText().toString().trim();
final String month = Month.getText().toString().trim();
final String cvv = CVV.getText().toString().trim();
final String pin = Pin.getText().toString().trim();
aaaaaa
JsonObjectRequest obreq = new JsonObjectRequest(Request.Method.POST, "https://api.myflex.ng/wallet/fund",
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
prgDialog.cancel();
String data = response.getString("status");
JSONObject obj = response.getJSONObject("data");
JSONObject transfer = obj.getJSONObject("transfer");
Payment_massage = transfer.getString("flutterChargeResponseMessage");
Payment_ref = transfer.getString("flutterChargeReference");
if (data.equalsIgnoreCase("error")) {
prgDialog.cancel();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
builder.setTitle("myFlex");
builder.setMessage("Connection Error. Please check Your Network Connection");
builder.setCancelable(false);
builder.setPositiveButton("OK", null);
builder.show();
} else {
prgDialog.cancel();
FragmentTransaction trans = getFragmentManager().beginTransaction();
trans.replace(R.id.change_transfer, new card_token());
trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
trans.addToBackStack(null);
trans.commit();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.toString(),Toast.LENGTH_LONG).show();
prgDialog.cancel();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
builder.setTitle("myFlex");
builder.setCancelable(false);
builder.setMessage("Connection Error. Please check Your Internet Connection ");
builder.setPositiveButton("OK", null);
builder.show();
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", User_Token);
headers.put("Content-Type", "application/json");
return headers;
}
@Override
public String getBodyContentType() {
return "application/json";
}
@Override
public byte[] getBody() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("amount", amount);
jsonObject.put("card", come());
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("Volley", "Error" + String.valueOf(jsonObject));
return jsonObject.toString().getBytes();
}
private JSONObject come() throws JSONException {
JSONObject params = new JSONObject();
try {
params.put("number", number);
params.put("expiry_month", month);
params.put("expiry_year", year);
params.put("cvv", cvv);
params.put("pin", pin);
Log.i("Volley", "Error" + String.valueOf(params));
} catch (JSONException e) {
Log.e("Volley", "Error" + params);
}
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
obreq.setRetryPolicy(new DefaultRetryPolicy(100 * 1000, 0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(obreq);
}
爲什麼不使用凌空 –
我可以使用,請給我選擇,告訴我該怎麼辦呢 –
你在郵遞員試過嗎? – Jeevanandhan