第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

$_POST 在 nginx 上為空

$_POST 在 nginx 上為空

PHP
人到中年有點(diǎn)甜 2021-12-03 18:43:54
我的問題似乎與$_POST 為空類似。Nginx OSx, $_POST 在 nginx 中為空,$_GET 已填充但 $_REQUEST 為空,但是我找不到適合我的解決方案。長(zhǎng)話短說,我無法將我的 POST 請(qǐng)求發(fā)送到server.php我的服務(wù)器上命名的文件。讓我們假設(shè) myserver.php只包含以下內(nèi)容:<?php var_dump($_REQUEST);我的sites-available/domain.tld文件包含以下內(nèi)容:server {    root /var/www/domain.tld/current/dist;    index index.html index.htm;    server_name domain.tld;    location / {        try_files $uri $uri/ index.php?$query_string =404;    }    location ~ \.php$ {            #limit_except POST {            #    allow 127.0.0.1;            #    deny  all;            #}            #if ( $request_method !~ ^POST$ ) {            #    return 405;            #}            include snippets/fastcgi-php.conf;            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;            #fastcgi_param REQUEST_METHOD $request_method;            fastcgi_param  REQUEST_METHOD     $echo_request_method;            fastcgi_param CONTENT_TYPE $content_type;            fastcgi_param CONTENT_LENGTH $content_length;            fastcgi_param REQUEST_BODY $request_body;            fastcgi_param QUERY_STRING $query_string;    }    location ~ /\.ht {            deny all;    }    listen 443 ssl; # managed by Certbot    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; # managed by Certbot    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; # managed by Certbot    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot}server {    server_name www.domain.tld;    return 301 $scheme://domain.tld$request_uri;}無論我提出什么“POST”請(qǐng)求,server.php都不會(huì)發(fā)送任何參數(shù)。輸出server.php將是array(0) {}一些其他信息:請(qǐng)求是在請(qǐng)求 URL 上進(jìn)行的: https://domain.tld/server.php請(qǐng)求方式: POST狀態(tài)代碼: 200 OK發(fā)送的 GET 請(qǐng)求https://domain.tld/server.php?foo=bar將向我顯示發(fā)送的正確foo變量,其值為bar如果需要,我可以提供有關(guān)請(qǐng)求本身的詳細(xì)信息。(axios在vue應(yīng)用程序中使用)。請(qǐng)指教...
查看完整描述

1 回答

?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

這個(gè)答案可能有點(diǎn)晚了,但為了其他遇到同樣問題的人:


問題原來是Content-Type標(biāo)題有 value application/json。當(dāng) PHP 解析數(shù)據(jù)以放入$_POST超級(jí)全局時(shí),它期望此標(biāo)頭具有值application/x-www-form-urlencodedor multipart/form-data,即 Web 標(biāo)準(zhǔn)內(nèi)容類型。接收application/json內(nèi)容類型數(shù)據(jù)時(shí),您必須從php://input流中訪問它。


解決方案最終看起來像這樣:


$json_string_data = file_get_contents('php://input');

$decoded_data = json_decode($json_string_data, true);

如果您的應(yīng)用程序希望數(shù)據(jù)在$_POST超級(jí)全局中可用,那么可以使用以下(無可否認(rèn)的 hacky)解決方案:


$json_string_data = file_get_contents('php://input');

$decoded_data = json_decode($json_string_data, true);

$_POST = $decoded_data;

或者,為簡(jiǎn)潔起見:


$_POST = json_decode(file_get_contents('php://input'), true);


查看完整回答
反對(duì) 回復(fù) 2021-12-03
  • 1 回答
  • 0 關(guān)注
  • 337 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)