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請求與郵差不同 –