4

下面的代码将实现一个简单的在线登录系统。

php 脚本路径在常量中定义authenticationURL(MainActivity.java 中的第 34 行)。它已经过 Postman 测试并且可以正常工作。loginButton及其方法也onClick()可以正常工作,因为Toast 嘿,我在这里!被展示。

但无论输入字段的值是否有效,当loginButton单击/点击时,Toast总是会显示 。意思StringRequestnull

使用的工具: xampp 7.2.11-0-VC15、Android Studio 3.2.1 & Genymotion 3.0.0 -> 自定义手机 (API 28)

MainActivity.java

package com.example.admin.test;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private EditText usernameEditText, passwordEditText;

    private static final String TAG = "OneTwoThree";

    private RequestQueue requestQueue;
    private StringRequest request;
    private static final String authenticationURL = "http://10.0.3.2:80/test/authenticationScript.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        usernameEditText = findViewById(R.id.usernameEditText);
        passwordEditText = findViewById(R.id.passwordEditText);
        Button loginButton = findViewById(R.id.loginButton);

        requestQueue = Volley.newRequestQueue(this);

        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                request = new StringRequest(Request.Method.POST, authenticationURL, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if(jsonObject.names().get(0).equals("success")) {
                                Toast.makeText(getApplicationContext(), "SUCCESS" + jsonObject.getString("success"), Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                            } else {
                                Toast.makeText(getApplicationContext(), "ERROR" + jsonObject.getString("error"), Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d(TAG, "Request response error.");
                        Toast.makeText(getApplicationContext(), "Hey, I'm up here!" , Toast.LENGTH_LONG).show(); // Just for debugging purpose
                    }
                })

                {
                    @Override
                    public String getBodyContentType() {
                        return "application/x-www-form-urlencoded; charset=UTF-8";
                    }

                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        HashMap<String, String> hashMap = new HashMap<>();
                        hashMap.put("username", usernameEditText.getText().toString());
                        hashMap.put("password", passwordEditText.getText().toString());

                        return hashMap;
                    }
                };

                requestQueue.add(request);
            }
        });

    }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/usernameEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:layout_marginEnd="8dp"
        android:autofillHints="@string/username"
        android:ems="10"
        android:hint="@string/username"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:targetApi="o" />

    <EditText
        android:id="@+id/passwordEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:layout_marginEnd="8dp"
        android:autofillHints="@string/password"
        android:ems="10"
        android:hint="@string/password"
        android:inputType="textPassword"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/usernameEditText"
        tools:targetApi="o" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="56dp"
        android:layout_marginEnd="8dp"
        android:text="@string/log_in"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/passwordEditText" />

</android.support.constraint.ConstraintLayout>

这是 Logcat 的部分(抱歉,由于文本限制而被截断):

2019-01-11 21:45:41.731 248-248/? E/hostapd: Configuration file: /vendor/etc/simulated_hostapd.conf
2019-01-11 21:45:41.735 248-248/? E/hostapd: Using interface wlan1 with hwaddr 02:00:00:00:01:00 and ssid "AndroidWifi"
2019-01-11 21:45:41.736 134-134/? E/SELinux: avc:  denied  { add } for interface=android.hardware.wifi.hostapd::IHostapd pid=248 scontext=u:r:execns:s0 tcontext=u:object_r:hal_wifi_hostapd_hwservice:s0 tclass=hwservice_manager permissive=1
2019-01-11 21:45:41.737 134-134/? E/SELinux: avc:  denied  { add } for interface=android.hidl.base::IBase pid=248 scontext=u:r:execns:s0 tcontext=u:object_r:hidl_base_hwservice:s0 tclass=hwservice_manager permissive=1
2019-01-11 21:45:42.155 320-320/? E/Netd: cannot find interface dummy0
2019-01-11 21:45:42.155 320-320/? E/XfrmController: netlink response contains error (Status[code: 95, msg: "[Operation not supported on transport endpoint] : Error netlink message"])
2019-01-11 21:45:42.155 320-320/? E/Netd: Failed to initialize XfrmController (Status[code: 95, msg: "[Operation not supported on transport endpoint] : Error netlink message"])
2019-01-11 21:45:42.155 320-320/? E/Netd: Unable to create netlink socket: Protocol not supported
2019-01-11 21:45:43.031 321-321/? E/ActivityRecognitionHardware: activity_recognition HAL is deprecated. class_init is effectively a no-op
2019-01-11 21:45:43.672 351-351/system_process E/UsbAlsaJackDetectorJNI: Can't register UsbAlsaJackDetector native methods
2019-01-11 21:45:43.798 351-370/system_process E/BluetoothAdapter: Bluetooth binder is null
2019-01-11 21:45:43.799 351-370/system_process E/BatteryExternalStatsWorker: no controller energy info supplied for telephony
2019-01-11 21:45:50.229 400-400/? E/EmulatedCamera_Factory: 2 cameras are being emulated. 0 of them are fake cameras.
2019-01-11 21:45:50.229 400-400/? E/EmulatedCamera_HotplugThread: createFileIfNotExists: Could not create file '/data/misc/media/emulator.camera.hotplug.0', error: 'Permission denied' (13)
2019-01-11 21:45:50.229 400-400/? E/EmulatedCamera_HotplugThread: createFileIfNotExists: Could not create file '/data/misc/media/emulator.camera.hotplug.1', error: 'Permission denied' (13)
2019-01-11 21:45:50.230 400-400/? E/CamProvider@2.4-impl: setUpVendorTags: Vendor tag operations not fully defined. Ignoring definitions.
2019-01-11 21:45:50.230 400-400/? E/CamProvider@2.4-impl: initialize: Vendor tag setup failed, will not be available.
2019-01-11 21:45:50.264 399-399/? E/SoundTriggerHalImpl: couldn't load sound trigger module sound_trigger.primary (No such file or directory)
2019-01-11 21:45:50.294 417-417/? E/network_profile_handler: init_all_network_profile_state: wlan: wlan0 phone:rmnet0
2019-01-11 21:45:50.472 408-408/? E/light: light_open lights bluetooth failed: -22
2019-01-11 21:45:50.472 408-408/? E/light: Light passthrough failed to load legacy HAL.
2019-01-11 21:45:50.472 408-408/? E/light: light_open lights wifi failed: -22
2019-01-11 21:45:50.472 408-408/? E/light: Light passthrough failed to load legacy HAL.
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type audio/x-ape
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type audio/ffmpeg
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/divx
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type audio/vnd.dts
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/x-flv
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type audio/vnd.rn-realaudio
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/vnd.rn-realvideo
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/vc1
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/ffmpeg
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type audio/x-ms-wma
2019-01-11 21:45:50.520 442-442/? E/MediaCodecsXmlParser: Cannot find the role for a decoder of type video/x-ms-wmv
2019-01-11 21:45:50.634 406-406/? E/hwcomposer: unknown display attribute 6
2019-01-11 21:45:50.674 429-429/? E/ExtCamUtils@3.4: loadFromCfg: Unable to load external camera config file '/vendor/etc/external_camera_config.xml'. Error: XML_ERROR_FILE_NOT_FOUND
2019-01-11 21:45:50.677 429-429/? E/CameraProviderManager: filterLogicalCameraIdsLocked: Failed to getCameraCharacteristics for id 0
2019-01-11 21:45:50.681 399-468/? E/EffectsConfig: Could not parse effect configuration in any of the default locations.
2019-01-11 21:45:50.681 399-468/? E/EffectsFactoryConfigLoader: Failed to parse XML configuration file
2019-01-11 21:45:50.683 429-429/? E/CameraProviderManager: filterLogicalCameraIdsLocked: Failed to getCameraCharacteristics for id 0
2019-01-11 21:45:50.684 429-476/? E/CameraProviderManager: filterLogicalCameraIdsLocked: Failed to getCameraCharacteristics for id 0
2019-01-11 21:45:50.684 429-429/? E/CameraProviderManager: filterLogicalCameraIdsLocked: Failed to getCameraCharacteristics for id 0
2019-01-11 21:45:50.685 429-476/? E/CameraService: onDeviceStatusChanged: State transition to the same status 0x1 not allowed
2019-01-11 21:45:50.695 413-413/? E/EffectsConfig: Could not parse effect configuration in any of the default locations.
2019-01-11 21:45:50.795 419-419/? E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found
2019-01-11 21:45:50.934 419-419/? E/HWComposer: getSupportedPerFrameMetadata: getSupportedPerFrameMetadata failed for display 0: Unsupported (8)
2019-01-11 21:45:52.438 351-376/system_process E/LocalDisplayAdapter: Default and active color mode is no longer available! Reverting to first available mode.
2019-01-11 21:45:52.507 534-539/? E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found
2019-01-11 21:45:52.850 351-351/system_process E/PackageManager: There should probably be a verifier, but, none were found
2019-01-11 21:45:52.889 413-413/? E/SoundTriggerHwService: could not read implementation properties
2019-01-11 21:45:52.976 351-364/system_process E/SystemServer: Unable to preload default resources
2019-01-11 21:45:53.009 351-351/system_process E/VibratorService: vibratorOff command failed (1).
2019-01-11 21:45:53.219 351-590/system_process E/EventHub: could not get driver version for /dev/input/mouse0, Not a typewriter
2019-01-11 21:45:53.291 145-145/? E/vold: Failed to read field SystemLocale: No such file or directory
2019-01-11 21:45:53.322 351-592/system_process E/StorageManagerService: Failed to read field SystemLocale
    android.os.ServiceSpecificException: Failed to read field SystemLocale (code 2)
        at android.os.Parcel.createException(Parcel.java:1956)
        at android.os.Parcel.readException(Parcel.java:1910)
        at android.os.Parcel.readException(Parcel.java:1860)
        at android.os.IVold$Stub$Proxy.fdeGetField(IVold.java:1094)
        at com.android.server.StorageManagerService.getField(StorageManagerService.java:2408)
        at com.android.server.StorageManagerService.copyLocaleFromMountService(StorageManagerService.java:982)
        at com.android.server.StorageManagerService.handleDaemonConnected(StorageManagerService.java:975)
        at com.android.server.StorageManagerService.access$900(StorageManagerService.java:171)
        at com.android.server.StorageManagerService$StorageManagerServiceHandler.handleMessage(StorageManagerService.java:572)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)
2019-01-11 21:45:53.350 351-590/system_process E/EventHub: could not get driver version for /dev/input/mice, Not a typewriter
2019-01-11 21:45:53.543 351-351/system_process E/WifiStateMachine: getWifiLinkLayerStats called without an interface
2019-01-11 21:45:53.555 351-351/system_process E/SupplicantStaIfaceHal: Can't call setDebugParams, ISupplicant is null
2019-01-11 21:45:53.642 351-351/system_process E/UsbPortManager: connectToProxy: usb hal service not found. Did the service fail to start?
    java.util.NoSuchElementException
        at android.os.HwBinder.getService(Native Method)
        at android.os.HwBinder.getService(HwBinder.java:91)
        at android.hardware.usb.V1_0.IUsb.getService(IUsb.java:48)
        at android.hardware.usb.V1_0.IUsb.getService(IUsb.java:52)
        at com.android.server.usb.UsbPortManager.connectToProxy(UsbPortManager.java:531)
        at com.android.server.usb.UsbPortManager.<init>(UsbPortManager.java:137)
        at com.android.server.usb.UsbService.<init>(UsbService.java:142)
        at com.android.server.usb.UsbService$Lifecycle.onStart(UsbService.java:73)
        at com.android.server.SystemServiceManager.startService(SystemServiceManager.java:126)
        at com.android.server.SystemServiceManager.startService(SystemServiceManager.java:113)
        at com.android.server.SystemServiceManager.startService(SystemServiceManager.java:72)
        at com.android.server.SystemServer.startOtherServices(SystemServer.java:1308)
        at com.android.server.SystemServer.run(SystemServer.java:432)
        at com.android.server.SystemServer.main(SystemServer.java:295)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)
2019-01-11 21:45:53.646 351-351/system_process E/HardwarePropertiesManagerService-JNI: Unable to get Thermal service.
2019-01-11 21:45:53.718 351-351/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.password.key: open failed: ENOENT (No such file or directory)
2019-01-11 21:45:53.718 351-351/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/password.key: open failed: ENOENT (No such file or directory)
2019-01-11 21:45:53.718 351-351/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.pattern.key: open failed: ENOENT (No such file or directory)
2019-01-11 21:45:53.719 351-351/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.gesture.key: open failed: ENOENT (No such file or directory)
2019-01-11 21:45:53.719 351-351/system_process E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gesture.key: open failed: ENOENT (No such file or directory)
2019-01-11 21:45:53.754 351-351/system_process E/IpConfigStore: Error opening configuration file: java.io.FileNotFoundException: /data/misc/ethernet/ipconfig.txt (No such file or directory)
2019-01-11 21:45:53.855 351-351/system_process E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /data/system/users/0/wallpaper_orig (No such file or directory)
2019-01-11 21:45:53.855 351-351/system_process E/WallpaperManagerService: Unable to apply new wallpaper
2019-01-11 21:45:53.865 351-614/system_process E/BluetoothAdapter: Bluetooth binder is null
2019-01-11 21:45:53.866 351-614/system_process E/BluetoothAdapter: Bluetooth binder is null
2019-01-11 21:45:53.933 436-457/? E/MediaExtractorFactory: couldn't opendir(/vendor/lib/extractors)
2019-01-11 21:45:53.972 351-370/system_process E/BatteryExternalStatsWorker: no controller energy info supplied for wifi
2019-01-11 21:45:53.972 351-370/system_process E/BatteryExternalStatsWorker: no controller energy info supplied for telephony
2019-01-11 21:45:53.991 320-342/? E/IptablesRestoreController: iptables error:
    ------- COMMAND -------
    *filter
    -I bw_INPUT -m quota2 ! --quota 2097152 --name globalAlert
    -I bw_OUTPUT -m quota2 ! --quota 2097152 --name globalAlert
    COMMIT

    -------  ERROR -------
    iptables-restore: line 290 failed
    ----------------------
2019-01-11 21:45:54.003 320-342/? E/IptablesRestoreController: iptables error:
    ------- COMMAND -------
    *filter
    -I bw_INPUT -m quota2 ! --quota 2097152 --name globalAlert
    -I bw_OUTPUT -m quota2 ! --quota 2097152 --name globalAlert
    COMMIT

    -------  ERROR -------
    ip6tables-restore: line 271 failed
    ----------------------
2019-01-11 21:45:54.048 672-690/? E/WebViewLoader-: Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe
2019-01-11 21:45:54.061 442-442/? E/media.codec: Failed to allocate omx component 'OMX.google.ac3.decoder'  err=InvalidComponentName(0x80001002)
2019-01-11 21:45:54.063 320-342/? E/BandwidthController: Updating quota globalAlert failed (Status[code: 2, msg: "[No such file or directory] : fopen("/proc/net/xt_quota/globalAlert", "we") failed"])
2019-01-11 21:45:54.072 404-404/? E/GnssHAL_GnssInterface: getExtensionAGnss: AGnss interface not implemented by HAL
2019-01-11 21:45:54.072 404-404/? E/GnssHAL_GnssInterface: getExtensionGnssMeasurement: GnssMeasurement interface not implemented by HAL
2019-01-11 21:45:54.072 404-404/? E/GnssHAL_GnssInterface: getExtensionGnssConfiguration: GnssConfiguration interface not implemented by HAL
2019-01-11 21:45:54.072 404-404/? E/GnssHAL_GnssInterface: getExtensionGnssGeofencing: GnssGeofencing interface not implemented by HAL
2019-01-11 21:45:54.073 404-404/? E/GnssHAL_GnssInterface: gnss flp hw_get_module failed: -2
2019-01-11 21:45:54.073 404-404/? E/GnssHAL_GnssInterface: getExtensionGnssBatching: GnssBatching interface is not implemented by HAL
2019-01-11 21:45:54.111 351-351/system_process E/LocationManagerService: no geocoder provider found
2019-01-11 21:45:54.127 351-351/system_process E/ActivityRecognitionHardware: activity_recognition HAL is deprecated. is_supported is effectively a no-op
2019-01-11 21:45:54.128 351-351/system_process E/ActivityRecognitionProxy: ServiceWatcher could not start.
2019-01-11 21:45:54.128 351-365/system_process E/GnssLocationProvider: Unable to initialize GNSS Xtra interface
2019-01-11 21:45:54.132 351-365/system_process E/GnssLocationProvider: no AGPS interface in set_agps_server
2019-01-11 21:45:54.167 351-365/system_process E/GnssLocationProvider: Unable to initialize GNSS Xtra interface
2019-01-11 21:45:54.167 351-365/system_process E/GnssLocationProvider: no AGPS interface in set_agps_server
2019-01-11 21:45:54.167 351-365/system_process E/GnssBatchingProvider: Failed to initialize GNSS batching
2019-01-11 21:45:54.173 442-442/? E/media.codec: Failed to allocate omx component 'OMX.google.mp2.decoder'  err=InvalidComponentName(0x80001002)
2019-01-11 21:45:54.231 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.h264.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.231 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.h264.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.237 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.h263.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.237 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.h263.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.244 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.hevc.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.244 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.hevc.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.248 442-442/? E/media.codec: Failed to allocate omx component 'OMX.google.mpeg2v.decoder'  err=InvalidComponentName(0x80001002)
2019-01-11 21:45:54.250 442-442/? E/OMXNodeInstance: getExtensionIndex(0xea42cba0:google.mpeg4.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.250 442-442/? E/OMXNodeInstance: getExtensionIndex(0xea42cba0:google.mpeg4.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.257 442-442/? E/OMXNodeInstance: getExtensionIndex(0xea42cba0:google.vp8.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.257 442-442/? E/OMXNodeInstance: getExtensionIndex(0xea42cba0:google.vp8.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.265 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.vp9.decoder, OMX.google.android.index.configureVideoTunnelMode) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.265 442-456/? E/OMXNodeInstance: getExtensionIndex(0xea42c8a0:google.vp9.decoder, OMX.google.android.index.enableAndroidNativeBuffers) ERROR: UnsupportedIndex(0x8000101a)
2019-01-11 21:45:54.290 442-456/? E/OMXNodeInstance: getConfig(0xea42cba0:google.h263.encoder, ConfigAndroidIntraRefresh(0x6f60000a)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.300 442-456/? E/OMXNodeInstance: getConfig(0xea42cba0:google.mpeg4.encoder, ConfigAndroidIntraRefresh(0x6f60000a)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.317 442-456/? E/OMXNodeInstance: getConfig(0xea42cba0:google.vp8.encoder, ConfigAndroidIntraRefresh(0x6f60000a)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.382 442-442/? E/OMXNodeInstance: getConfig(0xea42c900:google.vorbis.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.551 442-456/? E/OMXNodeInstance: getConfig(0xea42c900:google.vorbis.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.667 442-456/? E/OMXNodeInstance: getConfig(0xea42c900:google.vorbis.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001)
2019-01-11 21:45:54.679 767-767/? E/wpa_supplicant: global ctrl interface @android:wpa_wlan0 matches ctrl interface wlan0 - do not open per-interface ctrl interface
2019-01-11 21:45:54.690 767-767/? E/wpa_supplicant: global ctrl interface @android:wpa_wlan0 matches ctrl interface wlan0 - do not open per-interface ctrl interface
2019-01-11 21:45:54.724 634-819/com.android.inputmethod.latin E/ActivityThread: Failed to find provider info for user_dictionary
2019-01-11 21:45:54.863 412-412/? E/android.hardware.wifi@1.0-service: Failed to register radio mode change callback
2019-01-11 21:45:54.863 412-412/? E/android.hardware.wifi@1.0-service: Failed to set DFS flag; DFS channels may be unavailable.
2019-01-11 21:45:54.923 441-441/? E/wificond: No Offload Service available
2019-01-11 21:45:55.049 769-769/? E/CarrierIdProvider: read carrier list from ota pb failure: java.io.FileNotFoundException: /data/misc/carrierid/carrier_list.pb (No such file or directory)
2019-01-11 21:45:55.050 781-822/? E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found
2019-01-11 21:45:55.276 351-604/system_process E/SupplicantStaIfaceHal: Can't call setupIface, ISupplicantStaIface is null
2019-01-11 21:45:55.578 351-351/system_process E/BluetoothAdapter: Bluetooth binder is null

2019-01-11 21:45:55.859 442-456/? E/OMXNodeInstance: getConfig(0xea42c9c0:google.vorbis.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001)

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admin.test">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

URL 和脚本运行良好。观看下面的这些屏幕截图... 输出截图

使用 Postman(表单数据)和有效输入测试脚本、URL、服务器...

使用 Postman(表单数据)和无效输入测试脚本、URL、服务器...

使用 Postman (x-www-form-urlencoded) 和有效输入测试脚本、URL、服务器...

使用 Postman (x-www-form-urlencoded) 和无效输入测试脚本、URL、服务器...

4

2 回答 2

1

当您使用表单数据时,您必须添加 x-www-form-urlencoded。像这样做:

 @Override
public String getBodyContentType() {
    return "application/x-www-form-urlencoded; charset=UTF-8";
}

您的代码将类似于以下代码:

public class MainActivity extends AppCompatActivity {

private EditText usernameEditText, passwordEditText;

private RequestQueue requestQueue;
private StringRequest request;
private static final String authenticationURL = "http://10.0.3.2:80/test/authenticationScript.php";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    usernameEditText = findViewById(R.id.email);
    passwordEditText = findViewById(R.id.password);
    Button logIn = findViewById(R.id.signInUp);

    requestQueue = Volley.newRequestQueue(this);

    logIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            // Just for debugging purpose
            Toast.makeText(getApplicationContext(), "Hey, I'm up here!" , Toast.LENGTH_LONG).show();

            request = new StringRequest(Request.Method.POST, authenticationURL, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if(jsonObject.names().get(0).equals("success")) {
                            Toast.makeText(getApplicationContext(), "SUCCESS" + jsonObject.getString("success"), Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(getApplicationContext(), NextActivity.class));
                        } else {
                            Toast.makeText(getApplicationContext(), "ERROR" + jsonObject.getString("error"), Toast.LENGTH_SHORT).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }) {
              @Override
              public String getBodyContentType() {
             return "application/x-www-form-urlencoded; charset=UTF-8";
             }

                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("username", usernameEditText.getText().toString());
                    hashMap.put("password", passwordEditText.getText().toString());

                    return hashMap;
                }
            };

            requestQueue.add(request);
        }
    });

}

}

于 2019-01-12T11:01:25.480 回答
0

尝试使用 JsonObjectRequest

    JsonObjectRequest mJsonArrayRequest = new JsonObjectRequest(Request.Method.POST,url,null, new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject response) {
            Log.d("response", response.toString());

        }
    }
            , new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            NetworkResponse errorResponse = error.networkResponse;
            if (errorResponse != null && errorResponse.data != null) {
                Log.d("Error",errorResponse);
            }
        }
    });
    RequestQueue requestQueue = Volley.newRequestQueue(context);
    requestQueue.add(mJsonArrayRequest);
于 2019-01-11T21:01:29.050 回答