java - 建立 POST 请求以保存在 mySQL 上后,我的 InputStream 与我的网站返回 java.IO.FileNotFoundException
问题描述
在建立 POST 请求以保存在 MySQL 后,我的 InputStream 返回 java.IO.FileNotFoundException 和我的网站地址。一旦写入 MySQL 服务器,我就成功了,但它只是停止工作。我正在尝试将数据插入服务器上的 MySQL。用于打开连接和插入的 PHP 文件都是正确的,但是在后台异步执行它会返回 IOException。
这是我的代码
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;
下面是 IOException 是 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)
但是网站是正确的。我的错误是什么?
解决方案
在搜索了互联网并尝试了很多选项之后,我了解到 responseCode 409 表示存在冲突,并且这种冲突不一定总是发生。它与 NAME 冲突。我将我的 PHP 文件https://gdihq.com/evaluate/register.php更改为https://gdihq.com/evaluate/registerAccount.php,问题就消失了。
推荐阅读
- javascript - 如何根据前一个 for 循环在 for 循环中添加一个空行?
- datetime - 将当前时间与 Windows 批处理文件中上次修改的文件日期时间进行比较
- node.js - 错误:张量的形状必须由正整数组成,但形状为 [100,]
- java - 无限递归!如何转换?
- ruby-on-rails - 如何在 RSWAG 请求参数中添加组件?
- airflow - 气流依赖性阻止任务被安排
- abap - 我们什么时候在 SAP Hana 中有下推代码
- c# - ASP.net if else FluentValidation 条件
- mongodb - 启用身份验证后无法从 local.system.replset 中删除文档
- python - Kivy - 保存对象的值在弹出窗口中更改,以便在关闭它后,当我再次打开弹出窗口时,它会以新值打开