从移动设备 (android) 向 Wamp 服务器发送数据时出现 Volley authfailure 错误
Volley authfailure error when sending data from mobile (android) to Wamp server
我正在为我的数据库使用 SQL。我已经交叉验证了所有变量和参数的名称,它们都是正确的。我已经使用邮递员交叉验证了我的 PHP 脚本,我得到了正确的输出,但是当继续从移动设备发送数据时,我得到 com.android.volley.authfailureError.
以下是我的 android 代码...
package com.example.researchprojectv2;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
private EditText emp_ID, password;
private Button btn_submit;
private TextView txt;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emp_ID = findViewById(R.id.editTextNumber);
password = findViewById(R.id.editTextTextPassword);
btn_submit = findViewById(R.id.button);
txt = findViewById(R.id.login);
progressDialog = new ProgressDialog(this);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Login.class);
startActivity(intent);
}
});
btn_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
registerUser();
progressDialog.show();
progressDialog.setTitle("Please while registering");
}
});
}
private void registerUser() {
final String empID = emp_ID.getText().toString().trim();
final String passWD = password.getText().toString().trim();
progressDialog.setMessage("Registering User....");
StringRequest stringRequest = new StringRequest(Request.Method.POST,
Constants.URL_REGISTER,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.hide();
try {
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(getApplicationContext(), jsonObject.getString(
"message"), Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, hhh.class);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
progressDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("emp_id", empID);
params.put("password", passWD);
return params;
}
};
//200000 is the time in milliseconds adn is equal to 200 sec
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
200000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
}
}
日志报告(android工作室)
07/05 01:00:34: Launching 'app' on Xiaomi Redmi Note 7 Pro.
$ adb shell am start -n "com.example.researchprojectv2/com.example.researchprojectv2.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 19184 on device 'xiaomi-redmi_note_7_pro-5a14c494'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/searchprojectv: Late-enabling -Xcheck:jni
W/searchprojectv: miui_dex2oat: DeoptimizeBootImage: patch entry points of methods in boot image to interpreter bridge
W/searchprojectv: miui_dex2oat: OatFile: /data/app/com.example.researchprojectv2-R6-g_SKERFwg6QfVgTpG1A==/oat/arm64/base.odex Compiler-Filter = speed-profile
I/Perf: Connecting to perf service.
W/searchprojectv: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/searchprojectv: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
I/Adreno: QUALCOMM build : 89f10b9, I3d0e3ac366
Build Date : 12/25/18
OpenGL ES Shader Compiler Version: EV031.25.14.03
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
Build Config : S P 6.0.9 AArch64
I/Adreno: PFP: 0x016ee177, ME: 0x00000000
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
E/LB: fail to open file: No such file or directory
I/AssistStructure: Flattened final assist data: 3016 bytes, containing 1 windows, 10 views
I/DpmTcmClient: RegisterTcmMonitor from: $Proxy0
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
E/Volley: [6558] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.43.26/android/v1/Registeruser.php
E/Volley: [6558] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.43.26/android/v1/Registeruser.php
I/Toast: Show toast from OpPackageName:com.example.researchprojectv2, PackageName:com.example.researchprojectv2
I/searchprojectv: ProcessProfilingInfo new_methods=153 is saved saved_to_disk=1 resolve_classes_delay=8000
您遇到的问题似乎是由于使用被禁止的 HTTP 协议与服务器通信造成的。除非你明确配置你需要与之交谈的主机或 IP 地址。
首先,你应该在你的项目res
目录下创建xml
资源目录(只是一个简单的目录):
在其中创建一个 XML 文件。随意命名:
在此文件中声明您希望允许使用明文流量(又名 HTTP)的域或 IP:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">123.8.9.10</domain>
<!-- set domain name or IP instead of 123.8.9.10 -->
<!-- do not use protocol prefixes as http:// or https:// ftp:// ... -->
</domain-config>
</network-security-config>
注意允许应用程序使用 HTTP 的属性的使用:cleartextTrafficPermitted="true"
。 此属性是必需的。
下面是如何更新 AndroidManifest.xml
:
<application
android:networkSecurityConfig="@xml/network_security_config" <!-- setting configuration -->
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="UnusedAttribute">
...
</application>
我Google越来越多的是我自己解决的,通过在URL.
中的IP后面添加端口号
我正在为我的数据库使用 SQL。我已经交叉验证了所有变量和参数的名称,它们都是正确的。我已经使用邮递员交叉验证了我的 PHP 脚本,我得到了正确的输出,但是当继续从移动设备发送数据时,我得到 com.android.volley.authfailureError.
以下是我的 android 代码...
package com.example.researchprojectv2;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
private EditText emp_ID, password;
private Button btn_submit;
private TextView txt;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emp_ID = findViewById(R.id.editTextNumber);
password = findViewById(R.id.editTextTextPassword);
btn_submit = findViewById(R.id.button);
txt = findViewById(R.id.login);
progressDialog = new ProgressDialog(this);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Login.class);
startActivity(intent);
}
});
btn_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
registerUser();
progressDialog.show();
progressDialog.setTitle("Please while registering");
}
});
}
private void registerUser() {
final String empID = emp_ID.getText().toString().trim();
final String passWD = password.getText().toString().trim();
progressDialog.setMessage("Registering User....");
StringRequest stringRequest = new StringRequest(Request.Method.POST,
Constants.URL_REGISTER,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.hide();
try {
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(getApplicationContext(), jsonObject.getString(
"message"), Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, hhh.class);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
progressDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("emp_id", empID);
params.put("password", passWD);
return params;
}
};
//200000 is the time in milliseconds adn is equal to 200 sec
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
200000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
}
}
日志报告(android工作室)
07/05 01:00:34: Launching 'app' on Xiaomi Redmi Note 7 Pro.
$ adb shell am start -n "com.example.researchprojectv2/com.example.researchprojectv2.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 19184 on device 'xiaomi-redmi_note_7_pro-5a14c494'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/searchprojectv: Late-enabling -Xcheck:jni
W/searchprojectv: miui_dex2oat: DeoptimizeBootImage: patch entry points of methods in boot image to interpreter bridge
W/searchprojectv: miui_dex2oat: OatFile: /data/app/com.example.researchprojectv2-R6-g_SKERFwg6QfVgTpG1A==/oat/arm64/base.odex Compiler-Filter = speed-profile
I/Perf: Connecting to perf service.
W/searchprojectv: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/searchprojectv: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
I/Adreno: QUALCOMM build : 89f10b9, I3d0e3ac366
Build Date : 12/25/18
OpenGL ES Shader Compiler Version: EV031.25.14.03
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
Build Config : S P 6.0.9 AArch64
I/Adreno: PFP: 0x016ee177, ME: 0x00000000
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
E/LB: fail to open file: No such file or directory
I/AssistStructure: Flattened final assist data: 3016 bytes, containing 1 windows, 10 views
I/DpmTcmClient: RegisterTcmMonitor from: $Proxy0
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
E/Volley: [6558] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.43.26/android/v1/Registeruser.php
E/Volley: [6558] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.43.26/android/v1/Registeruser.php
I/Toast: Show toast from OpPackageName:com.example.researchprojectv2, PackageName:com.example.researchprojectv2
I/searchprojectv: ProcessProfilingInfo new_methods=153 is saved saved_to_disk=1 resolve_classes_delay=8000
您遇到的问题似乎是由于使用被禁止的 HTTP 协议与服务器通信造成的。除非你明确配置你需要与之交谈的主机或 IP 地址。
首先,你应该在你的项目res
目录下创建xml
资源目录(只是一个简单的目录):
在其中创建一个 XML 文件。随意命名:
在此文件中声明您希望允许使用明文流量(又名 HTTP)的域或 IP:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">123.8.9.10</domain>
<!-- set domain name or IP instead of 123.8.9.10 -->
<!-- do not use protocol prefixes as http:// or https:// ftp:// ... -->
</domain-config>
</network-security-config>
注意允许应用程序使用 HTTP 的属性的使用:cleartextTrafficPermitted="true"
。 此属性是必需的。
下面是如何更新 AndroidManifest.xml
:
<application
android:networkSecurityConfig="@xml/network_security_config" <!-- setting configuration -->
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="UnusedAttribute">
...
</application>
我Google越来越多的是我自己解决的,通过在URL.
中的IP后面添加端口号