PHP补丁方法curl请求发送

2ledvvac  于 2023-01-01  发布在  PHP
关注(0)|答案(1)|浏览(150)

我需要下面的代码PHP curl 请求到远程服务器。我无法做到这一点,没有从谷歌获得源代码
curl -X贴片

  • -header "内容类型:应用程序/json "
  • -标题"接受:应用程序/json "
  • -header "x应用程序接口令牌:API_令牌"
  • -标题"x-api-用户:API_USER "--数据'{"配置文件标识":"字符串","消息产品":["A2P","P2P"]}'
    "https://api.telnyx.com/messaging/numbers/{tn}"
sf6xfgos

sf6xfgos1#

一些php等价物可以是:
使用 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;

或者用狂饮:

<?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();

相关问题