您好,当我开发了一个检查电子邮件和密码的功能时,我在 REST API 中遇到了一个问题。在测试期间,我通过 Curl 控制台发送这些数据,它工作正常
C:\curlw32>curl -i -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost/mobile-app/api/login -d" {\"email\":\"test@gmail.com\",\"password\":\"
123\"}"
HTTP/1.1 200 OK
Date: Mon, 22 Apr 2013 06:21:37 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
Set-Cookie: PHPSESSID=63ba20f54ab6e233297c4bc022ae256c; path=/
Content-Length: 33
Set-Cookie: 63ba20f54ab6e233297c4bc022ae256c=DEFAULT%7C0%7C2M3TMlgUx3gTlaarYzHIdD28l8q9FTcNub
t55%2BUGpAo%3D%7C7456bf61db3500c8bb7b3bc38082a470ce4a2ad3; path=/
Vary: Accept-Encoding
Content-Type: text/html
"Email or password is incorrect!"
但是当我使用 Advanced Rest Client Application Chrome 扩展程序对其进行测试时,它会显示此错误
<html><head><title>Slim Application Error</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body><h1>Slim Application Error</h1><p>The application could not run because of the following error:</p><h2>Details:</h2><strong>Message:</strong> Trying to get property of non-object<br/><strong>File:</strong> D:\wamp\www\mobile-m-panels\api\index.php<br/><strong>Line:</strong> 39<br/><h2>Stack Trace:</h2>#0 D:\wamp\www\mobile-m-panels\api\index.php(39): Slim::handleErrors(8, 'Trying to get p...', 'D:\wamp\www\mob...', 39, Array)<br />
#1 [internal function]: authentication()<br />
#2 D:\wamp\www\mobile-m-panels\api\Slim\Route.php(392): call_user_func_array('authentication', Array)<br />
#3 D:\wamp\www\mobile-m-panels\api\Slim\Slim.php(1052): Slim_Route->dispatch()<br />
#4 D:\wamp\www\mobile-m-panels\api\index.php(28): Slim->run()<br />
#5 {main}</body></html>
任何机构都可以提出必要的改变吗?我捕获数据的代码是
$request = Slim::getInstance()->request();
$login_details = json_decode($request->getBody());