我正在使用 CakePHP 3 。
在我的控制器中,有一个操作可以接受POST
请求
public function func()
{
debug($this->request)
debug('abc');
if ($this->request->is(['patch', 'post', 'put'])) {
debug('xyz');
}
}
但是当我使用邮递员向URL发出POST请求时,debug('xyz');
没有执行。
debug($this->request)
正在给出以下响应
object(Cake\Http\ServerRequest) {
params => [
'controller' => 'IpnpaydotCom',
'action' => 'payDotComIpn',
'pass' => [],
'plugin' => null,
'_matchedRoute' => '/:controller/:action/*',
'_ext' => null,
'isAjax' => false
]
data => []
query => []
cookies => []
url => 'ipnpaydot-com/pay-dot-com-ipn'
base => ''
webroot => '/'
here => '/ipnpaydot-com/pay-dot-com-ipn'
trustProxy => false
[protected] _environment => [
'TZ' => 'America/New_York',
'REDIRECT_REDIRECT_REDIRECT_UNIQUE_ID' =>
'W2lBVQ1AAXb5W@kJqxSXHAAAAA4',
'REDIRECT_REDIRECT_REDIRECT_HTTPS' => 'on',
'REDIRECT_REDIRECT_REDIRECT_SSL_TLS_SNI' => 'app.helpneos.com',
'REDIRECT_REDIRECT_REDIRECT_STATUS' => '200',
'REDIRECT_REDIRECT_UNIQUE_ID' => 'W2lBVQ1AAXb5W@kJqxSXHAAAAA4',
'REDIRECT_REDIRECT_HTTPS' => 'on',
'REDIRECT_REDIRECT_SSL_TLS_SNI' => 'app.helpneos.com',
'REDIRECT_REDIRECT_STATUS' => '200',
'REDIRECT_UNIQUE_ID' => 'W2lBVQ1AAXb5W@kJqxSXHAAAAA4',
'REDIRECT_HTTPS' => 'on',
'REDIRECT_SSL_TLS_SNI' => 'app.helpneos.com',
'REDIRECT_HANDLER' => 'application/x-httpd-ea-php70',
'REDIRECT_STATUS' => '200',
'UNIQUE_ID' => 'W2lBVQ1AAXb5W@kJqxSXHAAAAA4',
'HTTPS' => 'on',
'SSL_TLS_SNI' => 'app.helpneos.com',
'HTTP_HOST' => 'app.helpneos.com',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84
Safari/537.36',
'HTTP_CACHE_CONTROL' => 'no-cache',
'HTTP_POSTMAN_TOKEN' => '5097ce19-c4a1-edd2-9713-edfd5876bbc0',
'HTTP_ACCEPT' => '*/*',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br',
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.9',
'PATH' => '/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache',
'SERVER_NAME' => 'app.helpneos.com',
'SERVER_ADDR' => '67.43.2.227',
'SERVER_PORT' => '443',
'REMOTE_ADDR' => '103.255.227.112',
'DOCUMENT_ROOT' => '/home/helpneos/app.helpneos.com/HelpNeos',
'REQUEST_SCHEME' => 'https',
'CONTEXT_PREFIX' => '/cgi-sys',
'CONTEXT_DOCUMENT_ROOT' => '/usr/local/cpanel/cgi-sys/',
'SERVER_ADMIN' => 'webmaster@app.helpneos.com',
'SCRIPT_FILENAME' => '/home/helpneos/app.helpneos.com/HelpNeos/webroot/index.php',
'REMOTE_PORT' => '41268',
'REDIRECT_URL' => '/webroot/index.php',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => '',
'REQUEST_URI' => '/ipnpaydot-com/pay-dot-com-ipn',
'SCRIPT_NAME' => '/webroot/index.php',
'ORIG_SCRIPT_FILENAME' => '/usr/local/cpanel/cgi-sys/ea-php70',
'ORIG_PATH_INFO' => '/webroot/index.php',
'ORIG_PATH_TRANSLATED' => '/home/helpneos/app.helpneos.com/HelpNeos/webroot/index.php',
'ORIG_SCRIPT_NAME' => '/cgi-sys/ea-php70',
'PHP_SELF' => '/webroot/index.php',
'REQUEST_TIME_FLOAT' => (float) 1533624661.1165,
'REQUEST_TIME' => (int) 1533624661,
'argv' => [],
'argc' => (int) 0,
'ORIGINAL_REQUEST_METHOD' => 'GET',
'HTTP_X_REQUESTED_WITH' => null
]
[protected] _input => null
[protected] _detectors => [
'get' => [
'env' => 'REQUEST_METHOD',
'value' => 'GET'
],
'post' => [
'env' => 'REQUEST_METHOD',
'value' => 'POST'
],
'put' => [
'env' => 'REQUEST_METHOD',
'value' => 'PUT'
],
'patch' => [
'env' => 'REQUEST_METHOD',
'value' => 'PATCH'
],
'delete' => [
'env' => 'REQUEST_METHOD',
'value' => 'DELETE'
],
'head' => [
'env' => 'REQUEST_METHOD',
'value' => 'HEAD'
],
'options' => [
'env' => 'REQUEST_METHOD',
'value' => 'OPTIONS'
],
'ssl' => [
'env' => 'HTTPS',
'options' => [
(int) 0 => (int) 1,
(int) 1 => 'on'
]
],
'ajax' => [
'env' => 'HTTP_X_REQUESTED_WITH',
'value' => 'XMLHttpRequest'
],
'flash' => [
'env' => 'HTTP_USER_AGENT',
'pattern' => '/^(Shockwave|Adobe) Flash/'
],
'requested' => [
'param' => 'requested',
'value' => (int) 1
],
'json' => [
'accept' => [
(int) 0 => 'application/json'
],
'param' => '_ext',
'value' => 'json'
],
'xml' => [
'accept' => [
(int) 0 => 'application/xml',
(int) 1 => 'text/xml'
],
'param' => '_ext',
'value' => 'xml'
],
'mobile' => object(Closure) {
},
'tablet' => object(Closure) {
}
]
[protected] _detectorCache => [
'ajax' => false,
'get' => true,
'head' => false,
'options' => false
]
[protected] stream => object(Zend\Diactoros\PhpInputStream) {
[protected] resource => resource
[protected] stream => 'php://input'
[private] cache => ''
[private] reachedEof => false
}
[protected] uri => object(Zend\Diactoros\Uri) {
base => ''
webroot => '/'
[protected] allowedSchemes => [
'http' => (int) 80,
'https' => (int) 443
]
[private] scheme => 'https'
[private] userInfo => ''
[private] host => 'app.helpneos.com'
[private] port => null
[private] path => '/ipnpaydot-com/pay-dot-com-ipn'
[private] query => ''
[private] fragment => ''
[private] uriString => null
}
[protected] session => object(Cake\Network\Session) {
[protected] _engine => null
[protected] _started => false
[protected] _lifetime => '5184000'
[protected] _isCLI => false
}
[protected] attributes => []
[protected] emulatedAttributes => [
(int) 0 => 'session',
(int) 1 => 'webroot',
(int) 2 => 'base',
(int) 3 => 'params'
]
[protected] uploadedFiles => []
[protected] protocol => null
[protected] requestTarget => null
}
我已从以下链接获得帮助:How to make post request with params and body in Postman