javascript - Getting data from PUT and DELETE on PHP sside from JS FormData

Im trying to learn REST API and got stuck with decoding data from JS {-code-6} using PUT for example

JS:

newF = async (e) => {
  let formData = new FormData();
  formData.append('key1', 'value1');
  formData.append('key2', 'value2');

  let response = await fetch(api, {
    method: 'PUT',
    body: formData
  });

  let result = await response.json();
  console.log(result)
}
newF()

PHP:

if ($_SERVER['REQUEST_METHOD'] === 'PUT') { 
    $myEntireBody = file_get_contents('php://input'); 
    echo  json_encode($myEntireBody);
}

This is closest that I got but the data returned to me is in strange format:


I dont know how to get values out of this with keys, I tried decoding/encoding {-code-4} {-code-5} in numerous ways and cant get values out.

I tried to follow among others: HTTP protocol's PUT and DELETE and their usage in PHP and Why PHP couldn't get $_POST data from Js {-code-6} fetch? with no luck.

I just want to know how to get values out of JS {-code-6} on PHP side and echo one off them back to JS response to confirm it.

Answer

Answer

---------42245388588346180811466041785 Content-Disposition: form-data; name="key1" value1

Answer

Answer

---------42245388588346180811466041785 Content-Disposition: form-data; name="key2" value2

Answer

Answer

---------42245388588346180811466041785--|||var damp|||$_PUT|||FormData

Source