我正在尝试将此curl命令转换为php:
curl -X POST "https://onfleet.com/api/v2/tasks" -u "456798b4f32516d4c75cf80bacc6f32a:" -d '{"destination":{"address":{"unparsed":"2829 Vallejo St, SF, CA, USA"},"notes":"Small green door by garage door has pin pad, enter *4821*"},"recipients":[{"name":"Blas Silkovich","phone":"+16505554481","notes":"Knows Neiman, VIP status."}],"completeAfter":1455151071727,"notes":"Order 332: 24oz Stumptown Finca El Puente, 10 x Aji de Gallina Empanadas, 13-inch Lelenitas Tres Leches","autoAssign":{"mode":"distance"}}'
有人可以帮忙吗?
您可以使用客户端URL库(cURL)。在-u
被设定的用户名(无密码),所以使用CURLOPT_USERPWD
。-d
设置数据以便使用CURLOPT_POSTFIELDS
:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://onfleet.com/api/v2/tasks');
curl_setopt($ch, CURLOPT_USERPWD, 'xxxxxxxxxxxx:');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"destination":{"address":{"unparsed":"2829 Vallejo St, SF, CA, USA"},"notes":"Small green door by garage door has pin pad, enter *4821*"},"recipients":[{"name":"Blas Silkovich","phone":"+16505554481","notes":"Knows Neiman, VIP status."}],"completeAfter":1455151071727,"notes":"Order 332: 24oz Stumptown Finca El Puente, 10 x Aji de Gallina Empanadas, 13-inch Lelenitas Tres Leches","autoAssign":{"mode":"distance"}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句