IONIC2/ANGULAR2 cannot access API created by laravel5.3

Source: Internet
Author: User

The Laravel 5.3 API has been configured to complete

    //category.service.ts    private headers = new Headers({'Content-Type': 'application/json','Accept':'application/json','Authorization':'Bearer '+window.localStorage.getItem('token')});    private heroesUrl = 'http://xingao.5188cms.com/api/user';  // URL to web api    private handleError(error: any): Promise {      console.error('An error occurred', error); // for demo purposes only      return Promise.reject(error.message || error);    }

This way to access, hint XMLHttpRequest cannot load http://xingao.5188cms.com/api/user. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. , it seems to be a cross-domain problem, but I use postman can be successfully obtained data

Step Two

I replaced the link with ahttp://xingao.5188cms.com/test.php

//test.php
  
   

Or not?XMLHttpRequest cannot load http://xingao.5188cms.com/test.php. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.

Step Three

I changed the link to one /test.json , but I can.

What is the reason for that ....

Reply content:

The Laravel 5.3 API has been configured to complete

    //category.service.ts    private headers = new Headers({'Content-Type': 'application/json','Accept':'application/json','Authorization':'Bearer '+window.localStorage.getItem('token')});    private heroesUrl = 'http://xingao.5188cms.com/api/user';  // URL to web api    private handleError(error: any): Promise {      console.error('An error occurred', error); // for demo purposes only      return Promise.reject(error.message || error);    }

This way to access, hint XMLHttpRequest cannot load http://xingao.5188cms.com/api/user. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. , it seems to be a cross-domain problem, but I use postman can be successfully obtained data

Step Two

I replaced the link with ahttp://xingao.5188cms.com/test.php

//test.php
  
   

Or not?XMLHttpRequest cannot load http://xingao.5188cms.com/test.php. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.

Step Three

I changed the link to one /test.json , but I can.

What is the reason for that ....

Access-Control-Allow-Origin
Cross-domain issues
This is the browser limit

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.