duandange7480 2018-05-21 10:16
浏览 56

为了使我的简单Ionic 3 WebApp GET请求正常工作,我需要在REST-API响应中设置哪些标头?

I'm stuck in creating my first Ionic app.

Scenario:

  1. Created a simple REST-API with Golang. It's working fine when i make the GET call in browser and / or Postman. The Output is:

    [
        {
            "id": 1,
            "name": "Leanne Graham"
        },
        {
            "id": 100,
            "name": "I COME FROM YOUR OWN REST-API!!!"
        }
    ]
    
  2. I created a simple Ionic 3 (with Angular 5) web app based on some tutorials. I just wanted to diplay my test data in an ionic-list with ngFor. This is working fine with some static (hard-coded) data.

  3. I then switched from hard-coded data to a REST-API. The tutorial suggested me to use http://jsonplaceholder.typicode.com/users. This also worked fine; I was able to display the users' data (tried only with id and name) in my ionic-list.
  4. I then switched to my own REST-API. I took similar (a little less) JSON content like the one from http://jsonplaceholder.typicode.com/users. See above.

Problem:

My ionic-list stays empty after fetching data from my own REST-API but works with any other public API.

Thoughts:

  • Since the content of my REST-API response is nearly the same as the one from http://jsonplaceholder.typicode.com/users i guess there is something wrong in my api-response headers. No tutorial covers the header stuff. This is why I didn't set them. I tried different headers in my response like w.Header().Set("content-type", "application/json") but this doesn't help.
  • Are there general headers I always have to set when responding to a GET request from an Ionic app?
  • When helpful I naturally will post my app's code here.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!