2

我想把这个终端命令转换成php curl格式,或者http post你能帮忙吗?

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 }'
4

2 回答 2

1
$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);
于 2017-11-24T10:05:51.793 回答
1

最简单的方法可能是使用 cURL。有关一些示例,请参见http://codular.com/curl-with-php

于 2020-02-03T09:20:03.763 回答