簡體   English   中英

無法使用 GET 方法但使用 POST 發送數據

[英]Can't send data with GET method but with POST

我正在 Php Slim 中構建 Rest API。 API 在本地主機上工作正常。 現在我把它放在實時服務器上。 問題是當我使用GET方法在正文中發送數據時,Postman 顯示錯誤: 500 Internal Server Error. . 但是將GET更改為POST時它工作正常。 我是后端新手,所以不明白問題是什么。 The index.php file of API is located in subdirectory as example.com/api/public/index.php so I made some changes in .htaccess but it's not working.

.htaccess

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /api/public/index.php [L,QSA]


# Don't listing directory
Options -Indexes
ErrorDocument 403 http://www.example.com/
# Follow symbolic links
Options +FollowSymLinks

# Default handler
DirectoryIndex index.php

# php -- END cPanel-generated handler, do not edit

我可以使用POST代替GET還是有問題?

問題是當我使用 GET 方法在正文中發送數據時

看一下規格

GET 請求消息中的有效負載沒有定義的語義; 在 GET 請求上發送有效負載正文可能會導致某些現有實現拒絕該請求。

雖然可以讓一些客戶端(例如 Postman)使用正文發出 HTTP GET 請求,並且可以讓一些服務器從 HTTP GET 請求中讀取正文,但它確實完全鎖定了一些其他客戶端(例如XMLHttpRequest 的瀏覽器 API 和 fetch)。

要么不要使用 GET 請求,要么不要為此使用請求正文。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM