PUT/DELETE request are not working

Username (e.g. epiz_XXX) or Website URL

testorangex.42web.io
(please specify the website or account you are asking about)

Trying to delete created resource and it is not possible (GET, POST works fine)

Frontend starting request like:

curl 'http://testorangex.42web.io/web/index.php/api/v2/pim/employees' \
  -X 'DELETE' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: _*** \
  -H 'Origin: http://testorangex.42web.io' \
  -H 'Referer: http://testorangex.42web.io/web/index.php/pim/viewEmployeeList' \
  -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36' \
  --data-raw '{"ids":[1]}' \
  --compressed \
  --insecure

or same request as fetch:

fetch("http://testorangex.42web.io/web/index.php/api/v2/pim/employees", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "accept-language": "en-US,en;q=0.9",
    "content-type": "application/json"
  },
  "referrer": "http://testorangex.42web.io/web/index.php/pim/viewEmployeeList",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": "{\"ids\":[1]}",
  "method": "DELETE",
  "mode": "cors",
  "credentials": "include"
});

Error Message

Access to XMLHttpRequest at 'https://errors.infinityfree.net/errors/403/' (redirected from 'http://testorangex.42web.io/web/index.php/api/v2/pim/employees') from origin 'http://testorangex.42web.io' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:187          DELETE https://errors.infinityfree.net/errors/403/ net::ERR_FAILED
(anonymous) @ xhr.js:187
e.exports @ xhr.js:13
e.exports @ dispatchRequest.js:53
u.request @ Axios.js:108
r.forEach.u.<computed> @ Axios.js:129
(anonymous) @ bind.js:9
value @ api.service.ts:93
deleteItems @ Employee.vue:360
(anonymous) @ Employee.vue:352
Promise.then (async)
onClickDelete @ Employee.vue:350
onClickAction @ Actions.vue?8a28:58
onClick @ Actions.vue?609a:12
ni @ runtime-core.esm-bundler.js:6708
ri @ runtime-core.esm-bundler.js:6717
ft @ runtime-core.esm-bundler.js:289
onClick @ Icon.vue?5d56:57
e.withContainer.Object.onClick.t.<computed>.t.<computed> @ Icon.vue?4ab7:17
ni @ runtime-core.esm-bundler.js:6708
ri @ runtime-core.esm-bundler.js:6717
n @ runtime-dom.esm-bundler.js:357
createError.js:16 Uncaught (in promise) Error: Network Error
    at e.exports (createError.js:16:15)
    at h.onerror (xhr.js:99:14)
e.exports @ createError.js:16
h.onerror @ xhr.js:99
Promise.then (async)
deleteItems @ Employee.vue:366
(anonymous) @ Employee.vue:352
Promise.then (async)
onClickDelete @ Employee.vue:350
onClickAction @ Actions.vue?8a28:58
onClick @ Actions.vue?609a:12
ni @ runtime-core.esm-bundler.js:6708
ri @ runtime-core.esm-bundler.js:6717
ft @ runtime-core.esm-bundler.js:289
onClick @ Icon.vue?5d56:57
e.withContainer.Object.onClick.t.<computed>.t.<computed> @ Icon.vue?4ab7:17
ni @ runtime-core.esm-bundler.js:6708
ri @ runtime-core.esm-bundler.js:6717
n @ runtime-dom.esm-bundler.js:357

(please share the FULL error message you see)

Other Information

I can GET and POST without problems

(other information and details relevant to your question)

I suspect this is a limitation of free hosting.
Only GET and POST will work.
Other commands are restricted

6 Likes

Yes, I can confirm this.

It has been said in other posts by Admin that because these methods are rare and sometimes suspicious (the latter I believe he said) that they decide to not allow it.

The GET and POST methods, implemented correctly should work just fine.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.