0
我想用laravel执行一个计划任务,它使用一个参数创建一个文章。Post方法与Guzzle不起作用/ Laravel 5
我已经检查过邮差我的POST,所以,我只需要打击myurl.com param ID = 188888例如。我得到它与邮递员合作。因此,首先,我制作Laravel命令:check:time,它只是执行帖子,然后,一旦我得到它的工作,我会安排它。
事情看起来命令什么也没做,我没有错误日志。
所以,真的,这不是那么容易调试它...
这是我的命令代码:
类检查时间延长命令 {
protected $signature = 'check:time {empId}';
protected $description = 'Check your time';
public function handle()
{
$client = new Client;
$numEmp = $this->argument('empId');
$response = $client->post('http://example.com/endpoint.php', ['ID' => $numEmp]);
var_dump($response);
}
}
当我打印$响应,我得到:
class GuzzleHttp\Psr7\Response#495 (6) {
private $reasonPhrase =>
string(2) "OK"
private $statusCode =>
int(200)
private $headers =>
array(6) {
'date' =>
array(1) {
[0] =>
string(29) "Wed, 01 Jun 2016 00:17:52 GMT"
}
'server' =>
array(1) {
[0] =>
string(22) "Apache/2.2.3 (Red Hat)"
}
'x-powered-by' =>
array(1) {
[0] =>
string(10) "PHP/5.3.15"
}
'content-length' =>
array(1) {
[0] =>
string(3) "146"
}
'connection' =>
array(1) {
[0] =>
string(5) "close"
}
'content-type' =>
array(1) {
[0] =>
string(24) "text/html; charset=UTF-8"
}
}
private $headerLines =>
array(6) {
'Date' =>
array(1) {
[0] =>
string(29) "Wed, 01 Jun 2016 00:17:52 GMT"
}
'Server' =>
array(1) {
[0] =>
string(22) "Apache/2.2.3 (Red Hat)"
}
'X-Powered-By' =>
array(1) {
[0] =>
string(10) "PHP/5.3.15"
}
'Content-Length' =>
array(1) {
[0] =>
string(3) "146"
}
'Connection' =>
array(1) {
[0] =>
string(5) "close"
}
'Content-Type' =>
array(1) {
[0] =>
string(24) "text/html; charset=UTF-8"
}
}
private $protocol =>
string(3) "1.1"
private $stream =>
class GuzzleHttp\Psr7\Stream#493 (7) {
private $stream =>
resource(311) of type (stream)
private $size =>
NULL
private $seekable =>
bool(true)
private $readable =>
bool(true)
private $writable =>
bool(true)
private $uri =>
string(10) "php://temp"
private $customMetadata =>
array(0) {
}
}
}
我检查$ numEmp是OK,al所以,我打印$回应,一切似乎要被罚款
正如我所说的,我也执行与邮差后,和它的作品,所以,我真的不明白这是怎么回事...
任何想法??
究竟是什么问题?你的回复代码是200 - 你的POST请求很好。 –
当我用postman执行这个帖子时,它添加了一个db行,但是当我用guzzle调用它时,它没有添加任何东西...我没有访问db只是一个UI,显示我行 –
Guzzle或Postman不应该在这种情况下 - POST请求是一个POST请求。您需要查看端点PHP脚本的响应 - 检查它是否包含错误消息或其他内容。出于某种原因,在您的Laravel任务中创建的POST请求与邮差不同 –