ServiceStack客户端发送OPTION而不是Get或post

时间:2018-01-31 17:26:49

标签: cors servicestack

我正在尝试使用typescript JsonServiceClient配置servicestack CorsPlugin。 客户端代码如下所示:



        const client = new JsonServiceClient( 'http://localhost:5000' );
        client.password = 'password';
        client.userName = 'username';
        client.get( new Authenticate() ).then( (authRes) => {
            console.log( authRes );
            let req = new CreateAccount();
            client.bearerToken = authRes.bearerToken;
            req.mail = 'demo';
            client.post( req ).then( (res) => {
                console.log( res );
            } );
        } );






            Plugins.Add(new CorsFeature(
                allowedMethods: "GET, POST, PUT, DELETE, OPTIONS",
                allowedHeaders: "Content-Type, Allow, Authorization",
                allowCredentials: true,
                allowOriginWhitelist: new[]
                    {"http://localhost:3000", "https://www.app.production.com"}));




当客户端发送请求时,它认为是GET但在控制台中它显示为OPTIONS,并且实际接收数据。所以它有点运行,但没有正确的http动词。任何人都可以建议我做错了什么?感谢

1 个答案:

答案 0 :(得分:1)

当您创建CORS Request时,浏览器会自动发送预检OPTIONS请求,以确定服务器是否批准来自原始网站的COR请求。