How can I access my local REST api from my android device?

后端 未结 4 1397
名媛妹妹
名媛妹妹 2021-02-13 14:03

I have a spring REST api running locally on my computer. I would like to consume this api for android development.

Here is my get request:

public stati         


        
4条回答
  •  佛祖请我去吃肉
    2021-02-13 14:36

    SOLVED if anyone is interested:

    I managed to fix this issue by extending the class my original sendGet(final String url) was in as follows HttpClientUsage extends AsyncTask more information and a tutorial can be found here: AsyncTask tutorial

    I then had to configure my CORS settings on my local REST API as follows:

     cors:
            allowed-origins: "*"
            allowed-methods: GET, PUT, POST, DELETE, OPTIONS
            allowed-headers: "*"
            exposed-headers:
            allow-credentials: true
            max-age: 1800
    

    Thank you all for your help, it is much appreciated.

提交回复
热议问题