相关疑难解决方法(0)

为什么我收到OPTIONS请求而不是GET请求?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script>
$.get("http://example.com/", function(data) {
     alert(data);
});
</script>
Run Code Online (Sandbox Code Playgroud)

它对该URL执行OPTIONS请求,然后从不使用任何内容调用回调.

当它不是跨域时,它工作正常.

不应该只是jQuery与一个<script>节点进行调用,然后在加载时进行回调吗?我明白我无法得到结果(因为它是跨域的),但那没关系; 我只是希望电话通过.这是一个错误,还是我做错了什么?

jquery xmlhttprequest http-get http-options-method

278
推荐指数
3
解决办法
32万
查看次数

Yii2:我可以仅针对某些操作应用身份验证器行为吗?

我总是得到"你要求的证书无效." 但我需要有一个公共端点专门"查看"操作,每个人都可以访问whitout发送访问令牌并保持其他操作与令牌验证

这是我的Api控制器的一部分:

/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        'contentNegotiator' => [
            'class' => ContentNegotiator::className(),
            'formats' => [
                'application/json' => Response::FORMAT_JSON,
                //'application/xml' => Response::FORMAT_XML,
            ],
        ],
        'verbFilter' => [
            'class' => VerbFilter::className(),
            'actions' => $this->verbs(),
        ],
        'access' => [
            'class' => AccessControl::className(),
            'only' => ['view'],
            'rules' => [
                [
                    'actions' => ['view'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
            ],
        ],
        'authenticator' => [
            'class' => CompositeAuth::className(),
            'authMethods' => [
                HttpBasicAuth::className(),
                HttpBearerAuth::className(),
                QueryParamAuth::className(),
            ],
        ],
        'rateLimiter' …
Run Code Online (Sandbox Code Playgroud)

php api rest yii2

9
推荐指数
1
解决办法
9117
查看次数

标签 统计

api ×1

http-get ×1

http-options-method ×1

jquery ×1

php ×1

rest ×1

xmlhttprequest ×1

yii2 ×1