0

If I run a POST or GET method it runs fine but if I use PUT then I keep getting 403 Forbidden returned. I'm not sure why its doing this and was hoping someone could help me out.

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!";
}
ngplayground
  • 20,365
  • 36
  • 94
  • 173
  • Why are you making a PUT request with `'application/x-www-form-urlencoded'` data and then trying to decode it as JSON? – Quentin Oct 28 '14 at 10:34
  • Have you allowed your script to use the PUT Method? Show us your config line for that. Make sure the Patch is correct – Shaeldon Oct 28 '14 at 10:35
  • What does the server logs say? They usually tell you why they are forbidding access. – Quentin Oct 28 '14 at 10:36
  • 1
    Similar question: [link](http://stackoverflow.com/questions/1402229/why-web-servers-does-not-allow-put-and-delete) – Markus Oct 28 '14 at 10:38
  • A `403` means something like cross domain security issues. PUT, and DEL are often blocked. So you should check permissions, maybe blocked by webserver. It does not have much to do with the actual content or erroneous request, this would've been a `400` or `405`. – Timmetje Oct 28 '14 at 10:41

0 Answers0