我在我的Android应用程序和服务器上托管的PHP之间正确沟通吗?

时间:2017-02-05 06:42:17

标签: php android server client-server

我一直收到以下错误:

W/System.err: java.io.FileNotFoundException: http://zeuspower.xyz/createCus.php
W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
W/System.err:     at com.zeuspwr.zeuspower.backgroundWorker.doInBackground(backgroundWorker.java:52)
W/System.err:     at com.zeuspwr.zeuspower.backgroundWorker.doInBackground(backgroundWorker.java:22)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:841)

当我执行以下脚本时会发生这种情况:

public class backgroundWorker extends AsyncTask<String,Void,String>{

    Context context;
    AlertDialog alertDialog;
    backgroundWorker(Context ctx){
        context = ctx;
    }

    @Override
    protected String doInBackground(String... params) {

        String type = params[0];
        String createCus_url = "http://zeuspower.xyz/createCus.php";
        if(type.equals("createCustomer")){
            try {
                String email = params[2];
                String stripeToken = params[1];
                URL url = new URL(createCus_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                OutputStream outputStream = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
                String post_data = URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")+"&"+
                        URLEncoder.encode("stripeToken","UTF-8")+"="+URLEncoder.encode(stripeToken,"UTF-8");
                bufferedWriter.write(post_data);
                bufferedWriter.flush();
                bufferedWriter.close();
                outputStream.close();
                InputStream inputStream = httpURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
                String result="";
                String line="";
                while ((line=bufferedReader.readLine())!=null){
                    result+=line;
                }
                bufferedReader.close();
                inputStream.close();
                httpURLConnection.disconnect();
                return result;
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        alertDialog = new AlertDialog.Builder(context).create();
        alertDialog.setTitle("Customer ID");
    }

    @Override
    protected void onPostExecute(String result) {
        alertDialog.setMessage(result);
        alertDialog.show();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }
}

我相信它会在我到达输入行时发生。输入流字符集解码器是否正确?我不知道在哪里查看。该文件是真实的并保存在以下位置:

enter image description here

0 个答案:

没有答案