【问题标题】:Breeze EntityQuery.from() withParameters POST to API not working微风 EntityQuery.from() withParameters POST 到 API 不起作用
【发布时间】:2018-08-09 08:42:08
【问题描述】:

我有这样的代码和平:

function getSopMatches(data) {

        return EntityQuery.from('GetSopMatches')
            .withParameters({
                $method: 'POST',
                $encoding: 'JSON',
                $data: data
            })
            .using(manager).execute()
            .then(success)
            .catch(_queryFailed);

        function success(response) {
            return response.results;
        }
    }

它是通过这个调用的:

playerService.getSopMatches({ playerId: vm.player.id, competitionId: career.competitionId, seasonId: career.seasonId, teamId: career.teamId }).then(function (results) { //do something with it });

在我的 MVC 控制器 (BreezeController) 中,方法如下:

[HttpPost]
    public IQueryable<object> GetSopMatches(SopMatch sop)
    {
        //this method is not called, I get a 405 Method not Allowed
    }

不知何故,实际调用是 GET,而不是 POST,因此我收到 405 Method not Allowed 错误消息。

我在同一个项目(客户端 javascript/breeze 调用和服务器端 mvc 控制器方法)中还有其他可以正常工作的代码。

有谁知道我做错了什么,或者为什么将其更改为 GET 方法?

【问题讨论】:

    标签: post breeze http-status-code-405


    【解决方案1】:

    经过一天的尝试和失败,我找到了解决方案。

    似乎我在角度控制器中注入了微风,这导致了问题。当微风被注入控制器或服务时,它会弄乱 POST 的 URL,因此您会收到 405(因为 URL 已更改)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 2016-12-23
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多