我想把这个终端命令转换成php curl格式,能帮忙吗?
curl -i -k -3 -X PATCH "http://localhost:8080/api/v2/db/_table/todo/1" \
-H "X-DreamFactory-Api-Key: <api key for app in the apps tab>" \
-H "X-DreamFactory-Session-Token: <session token from login response>" \
-H "Content-Type: application/json" \
-d '{ "complete" : true }'
答案 0 :(得分:1)
最简单的方法可能是使用cURL。有关示例,请参见http://codular.com/curl-with-php。
答案 1 :(得分:0)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/api/v2/db/_table/todo/1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"complete\" : true }");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
$headers = array();
$headers[] = "X-Dreamfactory-Api-Key: <api key for app in the apps tab>";
$headers[] = "X-Dreamfactory-Session-Token: <session token from login response>";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);