dart: debugging client/server communication for dart client and existing rest api?

你离开我真会死。 提交于 2020-01-11 03:56:27

问题


I have a rest api (developed in django/python) which i run locally and want to develop a simple client application in dart. This client uses XMLHttpRequest to communicate to a local django development server. The problem is the default run configuration in the Dart Editor launches it's own web server and than either dartium or the system browser with dart2js. Which will both obviously violate the cross origin policy when i try to access my rest api.

I'm wondering what the best setup would be to test client/server communication - should i configure my rest api to proxy the :3030 port which is used by the dart editor and configure a launch configuration with a URL, or is there a way to tell the dart editor server to send a "Access-Control-Allow-Origin" http header (this would be really cool), or some chrome launch parameter to disable cross origin checking for XMLHttpRequests?

seems like an obviously stupid problem, but i haven't found any solutions described in the (dart) documentation, or in previous questions here.


回答1:


Once Access-Control-Allow-Origin: * header has been added to every response of your REST API (don't forget OPTIONS request - see perlight request), you should be able to use it without problem with XMLHttpRequest and debug as it was on the same server.

Under development you can also use --disable-web-security option to launch Dartium ( see Disable same origin policy in Chrome )



来源:https://stackoverflow.com/questions/13588864/dart-debugging-client-server-communication-for-dart-client-and-existing-rest-ap

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