Android客户端无法连接到PHP服务器

时间:2017-04-25 04:58:45

标签: php android ubuntu android-volley

作为字符串的图像应该从android客户端发送到PHP服务器 服务器端代码就是这个 *

<?php
    echo "fata";
    if (isset($_POST['image'])) {
      $data = $_POST['image'];
      $name= $_POST['name'];

      $decodedImage = base64_decode($image);
      $image_file=time().rand(1111,9999);
      $name=$name.$image_file;
      $base_path='/var/www/html/CGIR/Uploads/';


      file_put_contents($base_path.$name.".jpg", $decodedImage);
      echo "wow!!!! You did it awesome man ...!!!";
       }
      echo "here";

    ?>

*

在客户端出现错误:超时。所以,我最初将时间设置为5000。但是客户端一直试图连接它并且它没有连接到服务器。我尝试在浏览器中使用相同的上传网址,但它确实有效。而apache也正常运行。我也试过禁用防火墙。但似乎没有任何效果。 这是android方面

                    //Showing the progress dialog
                    final ProgressDialog loading =ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
                    StringRequest stringRequest = new     StringRequest(Request.Method.POST, UPLOAD_URL,new Response.Listener<String>() {
                            @Override
                            public void onResponse(String s) {
                                        //Disimissing the progress dialog
                                    loading.dismiss();
                                    //Showing toast message of the response
                                    Toast.makeText(MainActivity.this, s , Toast.LENGTH_LONG).show();
                                }
                        },
                            new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError volleyError) {    
                                //Dismissing the progress dialog
                                System.out.println("Fama"+volleyError);
                                loading.dismiss();

                            //Showing toast
                                  try{
                                Toast.makeText(MainActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();}
                                catch(Exception     E){System.out.println("Exception occured"+E);}
                        }
                        }){
                        @Override
                       protected Map<String, String> getParams() throws AuthFailureError {
                             //Converting Bitmap to String
                            String image = getStringImage(bitmap);

                        //Getting Image Name
                            String name = editTextName.getText().toString().trim();

                        //Creating parameters
                            Map<String,String> params = new Hashtable<String, String>();

                            //Adding parameters
                            params.put(KEY_IMAGE, image);
                            params.put(KEY_NAME, name);

                            //returning parameters
                            return params;
                    } 
                };

                //Creating a Request Queue
               RequestQueue requestQueue = Volley.newRequestQueue(this);

                //Adding request to the queue
               requestQueue.add(stringRequest);
               stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                        50,
                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            }

0 个答案:

没有答案