HttpRequest and "Access-Control-Allow-Origin."

1,663 views
Skip to first unread message

jorat134617

unread,
Aug 26, 2012, 1:48:53 AM8/26/12
to mi...@dartlang.org
I'm trying to develop an application that need to communicate with a remote server. Everytime I try to communicate to my remote server, I get the message "Access-Control-Allow-Origin.". Is there a way in bypass that problem in some short of way and still keeping the project inside the Dart Editor?

Also, some short of ftp communication to send your file directly to your webserver will be great.

jorat134617

Darren Neimke

unread,
Aug 26, 2012, 1:54:16 AM8/26/12
to mi...@dartlang.org
Anything which ultimately runs inside of a browser is going to be subject to the access control restrictions which are enforced browsers.  Are you familiar with this type of issue and what your options are for developing browser based applications that can communicate across "origins"?

Darren Neimke




jorat134617

--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 

Seth Ladd

unread,
Aug 26, 2012, 1:54:34 AM8/26/12
to mi...@dartlang.org
Hello,

The browser's security model doesn't allow for cross-domain AJAX requests. This is not a Dart issue, but a browser issue. There are two ways you can get around this.

Use JSONP, a hack that uses a script tag to pull in cross domain resources. Here's a small library: https://github.com/chrisbu/DartJSONP

or

Setup CORS headers. If you control the server you are talking to, you can emit Access-Control-Allow-Origin: * header for all requests. This is the standards compliant way to allow any remote origin to use AJAX (aka XMLHttpRequest) to connect to your server.

Do you control the server you are talking to?

Meanwhile, FTP relies on TCP, which the browser does not understand. It's possible to write a command line FTP client (or server) in Dart, as command-line Dart supports TCP.

Hope that helps,
Seth



jorat134617

--

jorat134617

unread,
Aug 26, 2012, 2:04:42 AM8/26/12
to mi...@dartlang.org
Actually, this is what I did have in mind. Add the Access-Control-Allow-Origin to the header. I'm not sure how Dart Editor works for the hosting of file, but there is a website host inside of it and it will be nice if we could activate a parameter that adds the Access-Control-Allow-Origin. This way, we could test our Dart code without having to upload our code to a remote server.

jorat134617

unread,
Aug 26, 2012, 2:13:15 AM8/26/12
to mi...@dartlang.org
I found the answer to my question. You can add the parameter "--disable-web-security" to chrome.exe to disable cross domain check.

To do so, go in "Manage Launches..." and in the project you need to disable the security, add "--disable-web-security" where it said: Arguments.

jorat134617

Nguyen Duc Tien

unread,
Mar 17, 2014, 12:38:39 PM3/17/14
to mi...@dartlang.org
Thank for this advice. It's really correct.
Reply all
Reply to author
Forward
0 new messages