Volley authfailure error when sending data from mobile (android) to Wamp server

0

I am using SQL for my database. I have cross-verified all names of the variables and parameters they are correct. I have cross-verified my PHP script using postman snd I am getting correct output but when moving on to send data from the mobile I am getting com.android.volley.authfailureError.

Following is my android code...

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);
    }
}

log report (android studio)

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
java
android
authentication
android-volley
asked on Stack Overflow Jul 4, 2020 by Sumit Singh • edited Jul 4, 2020 by Sumit Singh

2 Answers

1

Looks like the issue you have is caused by talking to a server using HTTP protocol which is forbidden. Unless you explicitly configure hosts or IP addresses you need to talk to.

First of all, you should create xml resource directory under your project res directory (just a simple directory):

XML resources directory

Inside of it create an XML file. Name it how you want:

XML file - network security config

Inside of this file declare domains or IPs you would like to allow to use clear-text traffic (aka HTTP):

<?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>

Note the use of attribute that allows the application to use HTTP: cleartextTrafficPermitted="true". This attribute is required.

And here is how to update 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>
answered on Stack Overflow Jul 4, 2020 by Jenea Vranceanu
0

I Google it more and more resolved it by my self, by add port number after the IP in the URL.

answered on Stack Overflow Jul 4, 2020 by Sumit Singh

User contributions licensed under CC BY-SA 3.0