在同一个php文件中调用2个webservices

时间:2018-05-10 19:04:38

标签: php

我想通过一个api文件调用2个webservices,这就是我现在所拥有的:

    <?php
header('Access-Control-Allow-Origin: *'); 

$curl = curl_init();

$apiData = array(
        'FirstName'   => $_POST["FirstName"],
        'LastName'   => $_POST["LastName"],
        'email'   => $_POST["email"],
        'Phone'   => $_POST["phone"],
        'Country' => $_POST["country"],
        'password' => $_POST["password"],
        'jsonResponse' => 'true'
    );

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://my-url.com/api-reg.php",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => http_build_query($apiData),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

我想将相同的数据发布到另一个Web服务中 有关实施此事的任何提示吗?

谢谢!

0 个答案:

没有答案