国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

安裝webman/cors 程序還是報(bào)跨域錯(cuò)誤

問(wèn)題描述

安裝webman/cors 后 程序還是報(bào)跨域錯(cuò)誤,在StaticFile 靜態(tài)文件中間件里加了設(shè)置header還是無(wú)效,

程序代碼

class StaticFile implements MiddlewareInterface
{
    public function process(Request $request, callable $next): Response
    {
        // Access to files beginning with. Is prohibited
        if (strpos($request->path(), '/.') !== false) {
            return response('<h1>403 forbidden</h1>', 403);
        }
        /** @var Response $response */
        if ($request->method() == 'OPTIONS') {
            $response = response('');
        } else {
            $response = $next($request);
        }
        // Add cross domain HTTP header
        $response->withHeaders([
            'Access-Control-Allow-Origin'      => $request->header('origin', '*'),
            'Access-Control-Allow-Methods' =>  $request->header('access-control-request-method', '*'),
            'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', 'Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent, Authorization, X-Token'),
        ]);
        return $response;
    }
}

報(bào)錯(cuò)信息

Access to XMLHttpRequest at 'http://192.168.2.131:8585/upload/upload' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

截圖報(bào)錯(cuò)信息里報(bào)錯(cuò)文件相關(guān)代碼

操作系統(tǒng)及workerman/webman等框架組件具體版本

windows php8.0 webman1.5

1688 2 0
2個(gè)回答

wxvirus

默認(rèn)這個(gè)沒(méi)有配置吧,只是寫(xiě)了一個(gè)這么個(gè)中間件,沒(méi)有在config/middleware.php 里配全局使用;
我沒(méi)有安裝這個(gè),我都自己寫(xiě)一個(gè)

修改nginx.conf 跨域已經(jīng)可用了 ,但還是不知道代碼里應(yīng)該怎么實(shí)現(xiàn)~~~

server {   ....
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET,POST';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';  
}
  • wxvirus 2023-10-20

    我是自己寫(xiě)了一個(gè)

    class CrossDomain implements MiddlewareInterface
    {
    
        public function process(Request $request, callable $handler): Response
        {
            // 如果是options請(qǐng)求則返回一個(gè)空響應(yīng),否則繼續(xù)向洋蔥芯穿越,并得到一個(gè)響應(yīng)
            $response = strtoupper($request->method()) === 'OPTIONS' ? response('', 204) : $handler($request);
            // 給響應(yīng)添加跨域相關(guān)的http頭
            $response->withHeaders([
                'Access-Control-Allow-Credentials' => 'true',
                'Access-Control-Allow-Origin' => $request->header('origin', '*'),
                'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
                'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
            ]);
    
            return $response;
        }
    }
    return [
        // 全局作用域中間件
        '' => [
            // 跨域處理
            app\middleware\CrossDomain::class,
        ],
    ];
  • 我要當(dāng)省長(zhǎng) 2023-10-26

    啊 老哥牛逼

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??