cross domain rest api post put get delete

会有一股神秘感。 提交于 2019-12-11 07:17:36

问题


I built a REST api with GET, POST, PUT, DELETE for the angularjs single page application . Now my client wants to host REST api in separate domain and angularjs single page application in another domain. Here at development both angularjs application and REST api in same domain but if i move REST api to another domain my calls to REST api from angularjs application comes under cross domain requests, I tried with JSONP for call requests but only get requests are working and POST, PUT, DELETE requests are not working.

How do i solve this problem to make POST, PUT, DELETE requests with REST api that is in different domain.


回答1:


If you have access to modify REST api you could try to add this code at the top.

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');

You could change "*" to your AngularJS application's domain name. I hope that could help you.



来源:https://stackoverflow.com/questions/27164362/cross-domain-rest-api-post-put-get-delete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!