Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

php - My InputStream is returning java.IO.FileNotFoundException with my website after establishing a POST request to save on mySQL

My InputStream is returning java.IO.FileNotFoundException with my website address after establishing a POST request to save on MySQL. I was successful once writing to MySQL server but it just stopped working. I am trying to insert data to MySQL on my server. The PHP files for opening a connection and inserting are all correct but doing it in the background async is returning IOException.

Here is my code

String users_url = "https://gdihq.com/evaluate/register.php";
        String method = params[0];
        if(method.equals("Users")){
            String Date = params[1];
            String FirstName = params[2];
            String LastName = params[3];
            String Phone = params[4];
            String Email = params[5];
            try {
                URL url = new URL(users_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                OutputStream OS = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));
                String data = URLEncoder.encode("mDate","UTF-8") + "=" + URLEncoder.encode(Date,"UTF-8") + "&" +
                        URLEncoder.encode("FirstName","UTF-8") + "=" + URLEncoder.encode(FirstName,"UTF-8") + "&" +
                        URLEncoder.encode("LastName","UTF-8") + "=" + URLEncoder.encode(LastName,"UTF-8") + "&" +
                        URLEncoder.encode("Phone","UTF-8") + "=" + URLEncoder.encode(Phone,"UTF-8") + "&" +
                        URLEncoder.encode("Email","UTF-8") + "=" + URLEncoder.encode(Email,"UTF-8");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                OS.close();
                InputStream IS = httpURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(IS,"iso-8859-1"));
                String result = "";
                String line = "";
                while ((line = bufferedReader.readLine()) != null){
                    result += line;
                }
                bufferedReader.close();
                IS.close();

                httpURLConnection.disconnect();
                return result;


            } catch (MalformedURLException e) {
                Log.d(TAG,"Stacktrace Malfunctioned Begins here");
                Show(String.valueOf(e.getStackTrace()),ctx);
            } catch (IOException e) {
                Log.d(TAG,"Stacktrace Begins here");
                e.printStackTrace();

            }
        }
        return null;

Here under is the IOException is throws

java.io.FileNotFoundException: https://gdihq.com/evaluate/register.php
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:259)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at com.example.gdiapp.BackgroundTask.doInBackground(BackgroundTask.java:63)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at com.example.gdiapp.BackgroundTask.doInBackground(BackgroundTask.java:25)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at android.os.AsyncTask$3.call(AsyncTask.java:378)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-01-09 12:55:08.596 12651-31948/com.example.gdiapp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
2021-01-09 12:55:08.597 12651-31948/com.example.gdiapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2021-01-09 12:55:08.597 12651-31948/com.example.gdiapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2021-01-09 12:55:08.597 12651-31948/com.example.gdiapp W/System.err:     at java.lang.Thread.run(Thread.java:919)

But the website is correct. What is my error?

question from:https://stackoverflow.com/questions/65642412/my-inputstream-is-returning-java-io-filenotfoundexception-with-my-website-after

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After scouting the internet and tried many options, I understood the responseCode 409 means there is a conflict and this conflict does not necessarily happen all the time. It is conflict with NAME. I changed my PHP file https://gdihq.com/evaluate/register.php to https://gdihq.com/evaluate/registerAccount.php and the problem was gone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...