我刚刚用ubuntu 16.04,nginx 1.10.3和php 7.0创建了一个新的vps,并将我的工作站点复制到它。旧网站是在php5.6上运行完美无缺。
问题在于某些东西正在将我的编码加号转换为空格。 我可以证明这是真正的请求是使用文档检查器编码+ as%2B但直接卷曲测试也失败了:
Test 1:
curl "my_https_url" --data "details=asdf+%2B+asdf" --compressed
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 2:
curl "my_https_url" --data-urlencoded "details=asdf+%2B+asdf" --compressed
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 3:
$.post("my_https_url",{details:"asdf + asdf"})
Document Inspector Encoded Form Data: details=asdf+%2B+asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 4:
$.post("my_https_url",{details:"asdf %2B asdf"})
Document Inspector Encoded Form Data: details=asdf+%252B+asdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 5:
$.post("my_https_url",{details:"asdf+%2B+asdf"})
Document Inspector Encoded Form Data: details=asdf%2B%252B%2Basdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 6:
$.post("my_https_url",{details:encodeURI("asdf + asdf")})
Document Inspector Encoded Form Data: details=asdf%2520%2B%2520asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 7:
$.post("my_https_url",{details:encodeURIComponent("asdf + asdf")})
Document Inspector Encoded Form Data: details=details=asdf%2520%252B%2520asdf
array(1) { ["details"]=> string(11) "asdf + asdf" } <-- perfect
Test 8:
$.post("my_https_url",$('<form><input name="details" value="asdf + asdf"></form>').serialize())
Document Inspector Encoded Form Data: details=details=details=asdf+%2B+asdf
array(1) { ["details"]=> string(11) "asdf asdf" } <-- 3 spaces
Test 9:
$.post("my_https_url",encodeURIComponent($('<form><input name="details" value="asdf + asdf"></form>').serialize()))
Document Inspector Encoded Form Data: details%3Dasdf%2520%252B%2520asdf
array(0) {} <-- not working
<?php
var_dump($_POST);
// I am expecting "asdf + asdf"
是否存在导致此问题的php扩展或是否为nginx?我包括了两者的配置。
phpinfo:https://ibb.co/jZCxeQ
nginx config:
server {
listen 80;
# access_log /var/log/nginx/website.access_log;
error_log /var/log/nginx/website.error_log;
set $oldhost $host;
root PHP_FILES_LOCATION;
location ~* \.(?:ico|css|js|gif|jpg|png|html|htm)$ {
try_files $uri $uri/ /index.php;
expires 3d;
add_header Pragma public;
add_header Cache-Control "public";
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
index index.php index.htm index.html;
try_files $uri $uri/ /index.php;
}
location ~ json.php$ {
try_files $uri $uri/ /index.php;
# location ~ \..*/.*\.php$ {return 404;}
# expires 3d; add_header Pragma public; add_header
# Cache-Control "public";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
# fastcgi_index index.php;
client_max_body_size 80m;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .php$ {
#location ~ \..*/.*\.php$ {return 404;}
try_files $uri $uri/ /404.php?$args;
#expires 1d;
add_header Pragma public;
client_max_body_size 80m;
add_header Cache-Control "public";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
答案 0 :(得分:0)
在提交数据之前,您需要在值中对特殊字符进行编码。将您的值包裹在encodeURIComponent
。
$.post("my_https_url",{details:encodeURIComponent("asdf + asdf")})
答案 1 :(得分:0)
解决:我忘了我在主域上有一个代理服务器。我为@johnBaker创建了一个绕过代理服务器的子域,它可以正常工作。对代理配置的简单修复,它的工作原理!感谢大家参与我的野鹅追逐。