dongxun4110 2019-01-28 15:59 采纳率: 0%
浏览 19

PHP CURL转换

Can anyone help correct my code. I have been passed the API details shown in the comments section at the top and would like to convert into a CURL. I'm getting errors at the moment (some data changed to protect the real URL etc.)

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab