1
這是我用來上傳一張照片和一個數據的代碼。應用連續顯示發送對話,它不停止。無法上傳圖片和一個數據到服務器
private void uploadImage() {
String uploadUrl = "http://************.php";
HashMap<String, String> params = new HashMap<>();
params.put("photo_one",imageString(bitmap));
params.put("mobile",mName.getText().toString().trim());
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Sending Data....");
progressDialog.show();
JsonObjectRequest req = new JsonObjectRequest(uploadUrl, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
progressDialog.dismiss();
String success = (String) response.opt("success");
if (!success.equals("1"))
{
Toast.makeText(getApplicationContext(),"Invalid Username & Password...",Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
}
});
int x=2;// retry count
req.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48, x, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
我用調試模式來檢查發生了什麼,得到了這個答覆。
> req = {[email protected]} "[ ]
> http://*********.php 0xb5b5014d NORMAL null"
> this = {[email protected]} uploadUrl = "http://***********.php"
> params = {[email protected]} size = 2
> progressDialog = {[email protected]} req = {[email protected]} "[]
> http://***********.php 0xb5b5014d NORMAL null" x = 2
你知道郵遞員或圓弧這些都是使用檢查請求和響應的服務器嘗試使用它。 –
是的,我檢查了鏈接,它的工作正常。 –