PHP补丁方法curl请求发送



我需要下面的代码php curl请求远程服务器。我无法做到这一点,而不是从谷歌获取源


——header "Content-Type: application/json">
——header "Accept: application/json">
——header "x-api-token: API_TOKEN">
——header "x-api-user: API_USER"——数据"{"profile_id"string","msg_product":["A2P","P2P"}">
"https://api.telnyx.com/messaging/numbers/{tn}">

一些php等价的格式可以是:

using curl:

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.telnyx.com/messaging/numbers/'.$tn,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS =>'{"profile_id":"string","msg_product":["A2P","P2P"]}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'x-api-token: API_TOKEN',
'x-api-user: API_USER'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

或使用guzzle:

<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'x-api-token' => 'API_TOKEN',
'x-api-user' => 'API_USER'
];
$body = '{
"profile_id": "string",
"msg_product": [
"A2P",
"P2P"
]
}';
$request = new Request('PATCH', 'https://api.telnyx.com/messaging/numbers/'.$tn, $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();