DART中的客户端与PHP中的服务器通信:访问控制允许缺少原始标头 [英] Client in DART comunicate with server in PHP: access control allow origin headers missing
问题描述
这是我的客户:
import'dart:html';
void main(){
var request = new HttpRequest();
request.open('post','http://127.0.0.1/dartphp/index.php',async:true);
request.send(some data);
}
和我的伺服器:
<?php header(Access-Control-Allow-Origin:http://127.0.0.1:3030);
header(Access-Control-Allow-Methods:POST,GET,OPTIONS);
?>
< html>< body>
<?php
echopostback;
echo< pre>< br> post< br>;
echo $ HTTP_RAW_POST_DATA;
echo< / pre>< br>;
?>
< / body>< / html>
我在Dartium 3030上执行dart,让Apache在80上执行。
错误我得到是:
XMLHttpRequest不能加载 http://127.0.0.1/dartphp/index.php
。在所请求的资源上没有Access-Control-Allow-Origin头。原因' http://127.0.0.1:3030
'因此不允许访问。
我阅读了发送的文章php和dart之间的数据和 CORS与Dart,我如何让它工作?
,但在此期间语法已更改或解决方案不适用于我的问题,
-
第一个'on.readyStateChange.add'不再存在
-
必须更改的内容,所以可以'request.onReadyStateChange.listen((_)'到响应
服务器需要添加<$
您的网页最初从载入
http://127.0.0.1/dartphp/index.php
一个不同的域。 客户端向服务器发送一个请求,检查它是否以 Access-Control-Allow-Origin
code
$ b
尝试设置以下标题
访问控制允许原始,http://127.0.0.1 :3030
Access-Control-Allow-Methods,POST,GET,OPTIONS
This is my client:
import 'dart:html';
void main() {
var request = new HttpRequest();
request.open('post','http://127.0.0.1/dartphp/index.php',async: true);
request.send("some data");
}
and my server:
<?php header("Access-Control-Allow-Origin: http://127.0.0.1:3030");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
?>
<html><body>
<?php
echo "postback";
echo "<pre><br>post<br>";
echo $HTTP_RAW_POST_DATA;
echo "</pre><br>";
?>
</body></html>
I execute the dart in Dartium on 3030 and have Apache listening on 80.
The error I get is:
XMLHttpRequest cannot load http://127.0.0.1/dartphp/index.php
. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3030
' is therefore not allowed access.
I read the articles Send data between php and dart and CORS with Dart, how do I get it to work? but in the meantime syntax has changed or the solution is not applicable to my problem,
for the first 'on.readyStateChange.add' no longer exists
for the second 'request.response.headers.add' is not possible, as 'response' has no 'headers' defined
What has to be changed, so that can 'request.onReadyStateChange.listen((_)' to the response
The server needs to add the Access-Control-Allow-Origin
header not the client.
Your page is initally load from http://127.0.0.1:3030
and then wants to access http://127.0.0.1/dartphp/index.php
which is considered a different domain.
The client sends a request to the server to check if it responds with a Access-Control-Allow-Origin
header that fits the clients origin (which *
as wildcard does) after this the actual request is sent.
Try setting the following headers
"Access-Control-Allow-Origin", "http://127.0.0.1:3030"
"Access-Control-Allow-Methods", "POST, GET, OPTIONS"
这篇关于DART中的客户端与PHP中的服务器通信:访问控制允许缺少原始标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!