This is my function in my API I need to get the data from the form-data from the HTTP request.
I need to get the put values to update my data in my class query.
function method()
{
$method = $_SERVER['REQUEST_METHOD'];
return $method;
}
function updateUser()
{
$method = method();
if($method == 'PUT'){
$put_data = file_get_contents("php://input");
parse_str($put_data, $post_vars);
return $post_vars;
}else{
$status = '400 Bad Request';
return $status;
}
}
{"------WebKitFormBoundaryYKcobRh4FtrGCYaI Content-Disposition:_form-data;_name":"\"test\" test_value ------WebKitFormBoundaryYKcobRh4FtrGCYaI-- "}
This is what i get from the return $post_vars
I need to have test: test_value
Change the encoding of the request from multipart/form-data to application/x-www-form-urlencoded
Try replacing
$method = method();
if($method == 'PUT'){
//dosomething
}else{
//error
}
With
if (!($putData = fopen("php://input", "r"))){
throw new Exception("Can't get PUT data."); }
else{ //dostuff
}
for more information see: http://php.net/manual/en/features.file-upload.put-method.php