dpbdl44228 2018-11-17 11:16
浏览 70

使用Android Volley在laravel Passport中创建用户

We have Laravel + passport in our localhost (xampp). we want send request from android app to laravel app but below method have no response and no error and btnSubmit text be empty after sending request and we don't receive any access token. where is the problem of this method?

private void createUser(){
    final String url = "http://192.168.1.3/me2we/public/oauth/token";
    StringRequest stringRequest = new StringRequest(
            Request.Method.POST, url
            , new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    btnSubmit.setText(response);
                }
            }, new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError error) {
                    btnSubmit.setText(error.getMessage());
                }
            }
        ){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> params = new HashMap<String, String>();
            params.put("grant_type","password");
            params.put("client_id","2");
            params.put("client_secret","MKCFtd1U7pJ3J85iSu380SyGIVltWlYdrL334pbF");
            params.put("username","aminshabanzadeh1@gmail.com");
            params.put("password","A1b2C");
            params.put("scope","");
            return params;
        }
    };
    AppController.getInstance().addToRequestQueue(stringRequest);
}

did we select the correct ip address in request url? below is ipconfig command output in CMD:

Windows IP Configuration


Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . : test.com
   Link-local IPv6 Address . . . . . : fe80::7d4b:27f7:1e6d:f341%20
   IPv4 Address. . . . . . . . . . . : 10.253.31.78
   Subnet Mask . . . . . . . . . . . : 255.255.248.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 13:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::8852:3d75:59b3:a871%9
   IPv4 Address. . . . . . . . . . . : 192.168.1.3
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::41f9:ce63:37a2:134%10
   IPv4 Address. . . . . . . . . . . : 192.168.229.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::11b1:57cb:b413:26de%4
   IPv4 Address. . . . . . . . . . . : 192.168.230.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

laravel verfy token class:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}
  • 写回答

2条回答 默认 最新

  • dscqrkvr9562034621 2018-11-17 11:42
    关注

    In Laravel, with POST method, you need to verify Csrf Token for security. The easy way i knew is to ignore this check security.

    You may try: add your name method to the file in Laravel: Controllers/Middleware/VerifyCsrfToken.php

    if you know how to accept the verify and check it on Android Studio, please let me know VerifyCsrfToken class in Laravel

    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题