【问题标题】:Failed to load resource: the server responded with a status of 405 (Method Not Allowed) api加载资源失败:服务器响应状态为 405 (Method Not Allowed) api
【发布时间】:2018-06-18 17:53:12
【问题描述】:

当我使用 angularjs(frontend) 运行 http-server -o 以使用 symfony (backend) 中的 api 进行登录时,我收到此错误:

加载资源失败:服务器响应状态为 405 (不允许的方法) :8080/app/api/src/AppBundle/Controller/MainController.php

error Impossible d'accéder au serverur.

连接.js

'use strict';
    angular.module('myapplication.connection', ['ngRoute'])
    .config(['$routeProvider', function($routeProvider) {
      $routeProvider.when('/connection', {
        templateUrl: 'connection/connection.html',
        controller: 'connectionCtrl'
      });}])
    .controller('connectionCtrl', ['$http', '$scope', function($http, $scope) {
        $http.post('api/src/AppBundle/Controller/MainController.php', {formType:'connection'})
    .then(function (response) {
            $scope.connection = response.data;
        }, function(response) {
            $scope.connection = "Impossible d'accéder au serveur.";
        }); 
    }]);

connection.html(表单)

<div class="content">
    <h2>Connexion</h2>
    <div>{{ connection }}</div>
</div>

我该如何解决这个错误?

【问题讨论】:

    标签: angularjs node.js api symfony


    【解决方案1】:

    后端可能要求您在请求标头中设置 Content-Type 和/或 Accept。例如,请参阅here

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 2018-12-16
      • 1970-01-01
      • 2018-06-08
      • 2020-11-25
      • 2021-07-22
      • 2017-04-26
      • 1970-01-01
      相关资源
      最近更新 更多