簡體   English   中英

對php的POST請求僅出現在$ _GET var中

[英]POST requests to php only appearing in $_GET var

我正在將POST數據發送到php頁面,並通過var_dump($_POST)接收它。 但是, $_POST始終為空,並且$_GET包含值。 我確定它是POST請求,並且已經在Postman REST客戶端和cURL中進行了測試。 我正在使用PHP 5.5.3和Apache 2.2。 謝謝

編輯:我使用php腳本作為api,所以目前我正在測試使用上述工具來測試使用POST的請求。 例如,我正在使用此cURL請求curl -X POST http://dev/project/build/api/registrants.php?hello=there

我的$ _SERVER的內容(已在區域中刪除)

array(25) {
  ["HTTP_USER_AGENT"]=>
  string(11) "curl/7.37.1"
  ["HTTP_HOST"]=>
  string(3) "dev"
  ["HTTP_ACCEPT"]=>
  string(3) "*/*"
  ["PATH"]=>
  string(29) "/usr/bin:/bin:/usr/sbin:/sbin"
  ["SERVER_SIGNATURE"]=>
  string(0) ""
  ["SERVER_SOFTWARE"]=>
  string(67) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8za DAV/2 PHP/5.5.3"
  ["SERVER_NAME"]=>
  string(3) "dev"
  ["SERVER_ADDR"]=>
  string(9) "127.0.0.1"
  ["SERVER_PORT"]=>
  string(2) "80"
  ["REMOTE_ADDR"]=>
  string(9) "127.0.0.1"
  ["DOCUMENT_ROOT"]=>
  string(25) "/Applications/MAMP/htdocs"
  ["SERVER_ADMIN"]=>
  string(15) "you@example.com"
  ["SCRIPT_FILENAME"]=>
  string(59) "/Applications/MAMP/htdocs/project/build/api/registrants.php"
  ["REMOTE_PORT"]=>
  string(5) "51096"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["REQUEST_METHOD"]=>
  string(4) "POST"
  ["QUERY_STRING"]=>
  string(10) "hello=there"
  ["REQUEST_URI"]=>
  string(45) "/project/build/api/registrants.php?hello=there"
  ["SCRIPT_NAME"]=>
  string(34) "/project/build/api/registrants.php"
  ["PHP_SELF"]=>
  string(34) "/project/build/api/registrants.php"
  ["REQUEST_TIME_FLOAT"]=>
  float(1416256385.03)
  ["REQUEST_TIME"]=>
  int(1416256385)
  ["argv"]=>
  array(1) {
    [0]=>
    string(10) "hello=there"
  }
  ["argc"]=>
  int(1)
}

在您的<form>標記中,確保存在method="POST"屬性。

嗯,我遇到了同樣的問題,我發現錯誤是我使用了錯誤的標題,並且變量應該在請求的主體中傳遞,而不是作為URL參數傳遞。 我正在使用Postman生成POST請求,並且我已經填充了$ _GET和$ _POST為(array(0)),所以我讀到了有關$ _POST超全局變量的信息,並且僅在使用application / x-www-form-urlencoded時才被填充或multipart / form-data作為請求中的HTTP Content-Type,根據此處的PHP文檔: http : //php.net/manual/en/reserved.variables.post.php 然后,我閱讀了Postman手冊,並在打印屏幕上顯示了參數必須位於正文中,如會話請求正文中此處所述: https : //www.getpostman.com/docs/v6/postman/sending_api_requests/requests 正如史蒂夫(Steve)對您的問題的評論所述,使用curl時,此請求的格式應為:

curl -X POST --data "param1=value1&param2=value2" https://example.com/resource.cgi

暫無
暫無

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

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