I'm having issues using POST with a php REST server.
file_get_contents("php://input")
is adding additional quotes.
This is causing json_decode(file_get_contents("php://input"),true)
to
fail
i.e. I am posting stringified JSON
'{"someValue":0,"someOtherValue":1}'
PHP:
var_dump(file_get_contents("php://input"))
returns
string(173) "'{ "someValue" : 0, "someOtherValue" : "1"}'"
My PHP version is 5.3.10
To post the json, I am currently using the webstorm REST Client tool
Headers:
Accept: */*
Request Body:
Text: '{ "someValue" : 0, "someOtherValue" : "1"}'
I tried removing the outer quotes from the string in webstorm and it would work I.E. { "someValue" : 0, "someOtherValue" : "1"}
I moved to debugging in webstorm after initially hitting the bug in an angular application using angular ngResource
Controller
angular
.module('app.bookings')
.controller('BookAPuntController', BookAPuntController);
BookAPuntController.$inject(BookingServices);
function BookAPuntController(BookingServices) {
var data = {
someValue:0,
someOtherValue:1
};
BookingServices.save(JSON.stringify(data));
};
booking.dataservice.js
(function () {
'use strict';
angular
.module('app.data')
.factory('BookingServices', BookingServices);
BookingServices.$inject = ['$resource'];
/* @ngInject */
function BookingServices($resource) {
return $resource('rest/booking/:Id/:from/:to', null, {
'get': {method: 'GET', isArray: true},
});
}
})();