PHP CURL转换

时间:2019-01-28 15:59:09

标签: php curl

任何人都可以帮助纠正我的代码。我已经通过了顶部评论部分中显示的API详细信息,并希望转换为CURL。我目前遇到错误(更改了一些数据以保护真实的URL等)

<?php

/*

API DETAILS

Username: foo
password: bar

POST /api/v2/plannedGeofenceVisit HTTP/1.1
Host: dev-mf.testing.co.uk
Content-Type: application/json
Authorization: Basic <jumblecode>
cache-control: no-cache
Postman-Token: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
{
"vehicleIntRef": "vehicleRef",
"bookingRef": 223322,
"shedCode": "test2",
"plannedDispatchDate": "2020-01-25T09:55:00Z",
"estimatedArrivalDate": "2020-02-27T09:55:00Z"
}------WebKitFormBoundary7MA4YWxkTrZu0gW—


*/

$username = 'foo';
$password = 'bar';

    $curl = curl_init();

    curl_setopt_array($curl, array(CURLOPT_URL => "dev-mf.testing.co.uk",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD, $username . ":" . $password,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_HTTPHEADER => array(      
      "cache-control: no-cache",
      "postman-token: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      ),
    ));
    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }

?>

0 个答案:

没有答案