Javascript PHP PUT方法返回403 Forbidden

时间:2014-10-28 10:31:34

标签: javascript php mysql angularjs

如果我运行POST或GET方法它运行正常,但如果我使用PUT,那么我会继续返回403 Forbidden。我不知道为什么要这样做,并希望有人可以帮助我。

AngularJS

var id = {
    "locationData": locationData,
    "userData": userData,
    "url": url
}
$http({
    method: 'PUT',
    url: '/api/user',
    data: {
        'data': id
    },
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
}).success(function(content, status, headers, config) {
    $scope.url = data;
    $modal.open({
        templateUrl: '/assets/modals/modal-url.html',
        controller: ModalInstanceCtrl4,
        resolve: {
            url: function() {
                return $scope.url;
            }
        },
        scope: $scope.$new()
    });
});

PHP

<?php
require($_SERVER['DOCUMENT_ROOT'].'/api/db_connect.php');

if (!$db) {
    die('Could not connect: ' . mysql_error());
}


$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$method = $_SERVER['REQUEST_METHOD'];
$path = parse_url($url, PHP_URL_PATH);
$pathFragments = explode('/', $path);
$id = end($pathFragments);

switch (strtoupper($method)) {

    case "PUT":
        $postdata = json_decode(file_get_contents("php://input"));
        $src = (array)$postdata->data;

        echo "PUT";

        break;
    case "GET":

        $postdata = json_decode(file_get_contents("php://input"));
        $src = (array)$postdata->data;

        echo "GET";

        break;
    case "POST":

        $postdata = json_decode(file_get_contents("php://input"));
        $src = (array)$postdata->data;

        echo "POST";

        break;
    case "DELETE":
        echo "Your favorite color is green!";

        break;
    default:
        echo "Your favorite color is neither red, blue, or green!";
}

0 个答案:

没有答案