CakePHP3 CRUD API授权错误

时间:2017-02-28 19:55:39

标签: cakephp crud

我在CakePHP 3.x中使用FOC CRUD插件来提供API。

我在前端使用了一些Angular,通过http请求调用Cake API,按预期工作。

但是,当我尝试从API控制器调用一个Cake控制器时,从Cake控制器调用时,从Angular控制器调用时相同的方法被拒绝。我正在使用:

[Route("picture")]
    [HttpGet]
    public HttpResponseMessage GetPictureBlob()
    {
        HttpResponseMessage response = null;


        var localFilePath = HttpContext.Current.Server.MapPath("~/Content/Images/demo.jpg");

        if (!File.Exists(localFilePath))
        {
            response = Request.CreateResponse(HttpStatusCode.Gone);
        }
        else
        {

            var fStream = new FileStream(localFilePath, FileMode.Open, FileAccess.Read);
            // Serve the file to the client
            response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StreamContent(fStream)
            };
            response.Content.Headers.ContentDisposition =
            new ContentDispositionHeaderValue("attachment")
            {
                FileName = Path.GetFileName(fStream.Name)
            };
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            //response.Headers.Add("content-type", "application/octet-stream");

        }

        return response;

    }

如果我添加了更新'允许列表的方法允许PUT方法访问并执行更新。已经有一个Auth会话处于活动状态,但是当Cake发出http请求时,它似乎没有认识到已经有一个实时的auth会话。

如果我可以通过本地路径拨打api电话,我可以解决这个问题,但我不确定这是否可行,因为' http://foo.com'我得到了一个错误的URI"错误。有什么想法吗?

0 个答案:

没有答案