Code Monkey home page Code Monkey logo

Comments (7)

medz avatar medz commented on May 18, 2024

origins 添加你需要跨域的域,测试可以添加 *

例如:

$config = [
    'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
    'allow-headers'      => ['*'], // ex: Content-Type, Accept, X-Requested-With
    'expose-headers'     => [],
    'origins'            => ['*'], // 允许跨域只添加 * 即可
    'methods'            => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
    'max-age'            => 0,
];
$app->add(new Medz\Cors\Slim\Cors($config));

from cors.

sunyinggang avatar sunyinggang commented on May 18, 2024

origins 添加你需要跨域的域,测试可以添加 *

例如:

$config = [
    'allow-credentials' => false, // set "Access-Control-Allow-Credentials" 👉 string "false" or "true".
    'allow-headers'      => ['*'], // ex: Content-Type, Accept, X-Requested-With
    'expose-headers'     => [],
    'origins'            => ['*'], // 允许跨域只添加 * 即可
    'methods'            => ['*'], // ex: GET, POST, PUT, PATCH, DELETE
    'max-age'            => 0,
];
$app->add(new Medz\Cors\Slim\Cors($config));

还是遇到了问题,而且就算是我在nginx也设置一下允许跨域,也是会报错:Failed to load http://wx.simplesay.xin/user/index: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.

from cors.

medz avatar medz commented on May 18, 2024

@sunyinggang 好的,我再测试一下回复你~

from cors.

sunyinggang avatar sunyinggang commented on May 18, 2024

@sunyinggang好的,我再测试一下回复你〜

有没有测试通过呀

from cors.

medz avatar medz commented on May 18, 2024

@sunyinggang

Slim 框架支持演示.zip

这是我写给你的 Slim 框架继承 Cors 例子,包含了跨域测试,解压后请阅读 readme.md 文件

from cors.

sunyinggang avatar sunyinggang commented on May 18, 2024

@sunyinggang

Slim框架支持演示.zip

这是我写给你的Slim框架继承Cors例子,包含了跨域测试,解压后请阅读readme.md文件

感谢您的帮助,现在有效了,问题是我的new \Medz\Cors\Slim\Cors($setting),我没有附带第二个参数true,我发现如果去掉这个参数,就会无效,但是我在您的官方文档中并没有看到对这个的解释,是不是以后使用的时候默认都得带上这个参数,或者在官方实例中改为带第二参数的这种形式,会比较好

from cors.

medz avatar medz commented on May 18, 2024

@sunyinggang
https://github.com/medz/cors/blob/master/docs/using-by-slim.md#cors-middleware-__construct
在这里有讲两个参数,昨天发了一个新版本,第二个参数默认由 false 改为 true 了,其实第二个参数 false 无伤大雅,因为不同开启必须预检后,只需要验证 OPTIONS 请求即可的,第二个参数为 true 表示不管是不是 预检请求都携带,为 false 就是只有预检才携带跨域信息。我测试过如果在你发送的跨域请求前由预检就完全 ok 的~

from cors.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.