访问本地主机laravel应用程序路由到android studio失败 [英] accessing localhost laravel app routes to android studio failed

查看:106
本文介绍了访问本地主机laravel应用程序路由到android studio失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在android Studio3中开发一个android应用程序,它的背面是laravel.对于本地服务器,我由artizan创建了一个虚拟服务器.现在的问题是将本地服务器(127.0.0.1:8000)连接到android,为此,我在波纹管接口中尝试了太多baseUrl,例如:

I'm developing an android app in android Studio3 that its back is laravel. For the local server, I created a virtual server by artizan. Now the problem is connecting local server (127.0.0.1:8000) to android and for this, I tried too many baseUrl in bellow Interface like:

10.0.2.2:8008,10.0.3.2:8000,IP4,.............,:/

10.0.2.2:8008, 10.0.3.2:8000, IP4, ............., :/

接口:

interface ApiInterface {

    @GET("stocks.json")
    fun getStocks(): Call<StockResponse>

    companion object {
        val BASE_URL = "http://192.168.1.106:8000/api/"

        fun getClient(): ApiInterface{
            val retrofit = Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()

            return retrofit.create(ApiInterface::class.java)
        }
    }
}

最后,我为此项目尝试了一个外部服务器,但是对于本地项目却没有,所以,伙计,如果您解决了这个困扰不已的问题,将不胜感激...

And finally, I tried an external server for this project that it worked, But for local it didn't, So buddy, I would be appreciated if you resolve this distraught issue...

更新:伙计们感谢您的回答,我真的尝试了很多方法,最后,我发现laravel api路由在android studio中失败了,并且没有建立,这意味着:

UPDATE: Guys thank you for your response, I really tried many ways and finally, I found out that laravel api routes fail in the android studio and it is not founded, It means:

http://192.168.1.106:8000/file.json  (Worked-> specific file in local server )
http://192.168.1.106:8000/api/file  (Not Worked-> laravel route api)

推荐答案

我有一个php lumen项目,通常使用以下命令启动该项目:'php -S localhost:8000 -t public'这可以用邮递员作为我的网址是" http://localhost:8000/api/v1/login "

I have a php lumen project which I started usually using this command 'php -S localhost:8000 -t public' this is ok with post man as my url is "http://localhost:8000/api/v1/login"

在我的Android部分中,我的基本网址是" http://myip:8000/api/v1/登录",但它无法连接到本地服务器,并且无法全面调用onFailour方法(抛出ecxeption无法连接到服务器). 所以我使用此命令重新启动了服务器 "php -S myip:8000 -t public".然后,它开始给出响应. 警告: 1.两个设备都必须连接相同的wifi网络 2.要找到您的IP,请运行cmd,然后在控制台中输入ipconfig,然后按Enter

In my Android part my base url is "http://myip:8000/api/v1/login" but it can't connect to the local server and comprehensively calling onFailour method which throwing an ecxeption can't connect to the server. So what I did I restrat the server using this command "php -S myip:8000 -t public". Then it start giving response. Caution: 1.both device device must be connect with same wifi network 2.to find your ip, go to run type cmd then in console type ipconfig hit enter

这篇关于访问本地主机laravel应用程序路由到android studio失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆