동일한 출처에서만 Apache의 PHP 파일에 POST를 허용하는 방법은 무엇입니까?

동일한 출처에서만 Apache의 PHP 파일에 POST를 허용하는 방법은 무엇입니까?

제출 시 서버(Apache 2.4.48)의 .php 파일에 POST 요청을 성공적으로 보내는 HTML 양식이 포함된 웹사이트가 있습니다.

그러나 Javascript가 JS fetch()를 통해 제출을 처리하도록 하면 서버가 405 오류로 응답합니다.

그래서 두 POST에 대한 요청 및 응답 헤더를 분석했는데 거의 동일하므로 첫 번째 방법은 작동하고 다른 방법은 거부되는 이유가 혼란스럽습니다.

다음은 HTML 양식을 통해 전송할 때의 요청/응답입니다(느낌표는 POST 요청이 다른 부분입니다).

GENERAL
Request URL: https://example.com/php/script.php
Request Method: POST
Status Code: 302 
Remote Address: 160.153.133.187:443
Referrer Policy: origin-when-cross-origin


RESPONSE HEADERS
cache-control: max-age=0                    !
content-length: 0
content-type: text/html; charset=UTF-8
date: Sat, 14 Aug 2021 23:21:34 GMT
expires: Sat, 14 Aug 2021 23:21:34 GMT
location: https://example.com/pages/form-submitted.html#submitted
server: Apache
vary: User-Agent
x-powered-by: PHP/8.0.8


REQUEST HEADERS
:authority: example.com
:method: POST
:path: /php/script.php
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9     !
accept-encoding: gzip, deflate, br
accept-language: en-GB,en;q=0.9,es-ES;q=0.8,es;q=0.7,it-IT;q=0.6,it;q=0.5
cache-control: no-cache
content-length: 96
content-type: application/x-www-form-urlencoded     !
dnt: 1
origin: https://example.com
pragma: no-cache
referer: https://example.com/contact
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
sec-fetch-dest: document        !
sec-fetch-mode: navigate        !
sec-fetch-site: same-origin
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36


FORM DATA
name: Tai Zen
email: [email protected]
phone-number: 12345678910
privacy-consent: on
submit: 

대신 아래에는 fetch()를 사용하여 POST를 보낼 때의 요청/응답이 있습니다.

GENERAL
Request URL: https://example.com/php/script.php
Request Method: POST
Status Code: 302 
Remote Address: 160.153.133.187:443
Referrer Policy: same-origin


RESPONSE HEADERS
cache-control: max-age=2741
content-length: 0
content-type: text/html; charset=UTF-8
date: Sat, 14 Aug 2021 23:31:44 GMT
expires: Sun, 15 Aug 2021 00:17:26 GMT
location: https://example.com/405
server: Apache
vary: User-Agent
x-powered-by: PHP/8.0.8


REQUEST HEADERS
:authority: example.com
:method: POST
:path: /php/script.php
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-GB,en;q=0.9,es-ES;q=0.8,es;q=0.7,it-IT;q=0.6,it;q=0.5
cache-control: no-cache
content-length: 471
content-type: multipart/form-data; boundary=----WebKitFormBoundary28YayN0mmqwdpQh0
dnt: 1
origin: https://example.com
pragma: no-cache
referer: https://example.com/contact
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: same-origin
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

FORM DATA
name: Tai Zen
email: [email protected]
phone-number: 12345678910
privacy-consent: on
submit:

특정 파일에 대한 POST 요청을 허용하려면 서버 측을 변경해야 합니까?

그런데 외부 엔터티가 아닌 내가 작성한 JS에서만 POST 요청을 받고 싶은데 정확히 어떻게 해야 할지 모르겠습니다. 나는 제안 된 것을 시도했습니다이 답변, 작동하지 않았는데 서버에서 500 오류가 발생했습니다. 공유 호스팅 계획을 사용 중이고 Apache 설정에 대한 전체 액세스 권한이 없기 때문일 수 있다고 생각하지만 이것이 이유인지 확신할 수 없습니다.

관련 정보