php 504在WordPress中进行cURL请求时发生网关超时错误

70gysomp  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(136)

我在WordPress环境中尝试进行cURL请求时遇到了504网关超时错误。我已经包含了以下相关代码:

function welkvoxapi() {
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://wv{{wolkvox_server}}.wolkvox.com/api/v2/campaign.php?api=add_record&type_campaign={{type_campaign}}&campaign_id={{campaign_id}}&campaign_status={{campaign_status}}',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'[{
            "customer_name": "namewv",
            "customer_last_name": "field_3d8268c",
            "customer_id": "field_d3976af",
            "city": "field_5dd4679",
            "opt1": "field_9f10881",
            "opt3": "field_6d254ff",
            "opt4": "field_363c904",
            "opt5": "field_a5de87f",
            "opt6": "field_dc05404",
            "opt7": "field_9a9a683",
            "opt8": "field_383d50f",
            "email": "field_8981d35"  

}]',
  CURLOPT_HTTPHEADER => array(
    'wolkvox-token: {{token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

}
add_action('init', 'welkvoxapi');

字符串
我已经将以下cURL代码添加到我的WordPress主题的functions.php文件中,以与Wolkvox API进行交互。然而,当我保存代码时,页面无法加载,并且我遇到了“504 Gateway Time-out”错误。
Wolkvoks Documentation.
此外,我在AWS上托管我的WordPress网站,但我不确定这是否与遇到的问题有关。
我已经替换了CURLOPT_URL和令牌中的相应信息。
我将感谢任何关于解决“504网关超时”问题的指导。此外,如果有任何考虑或最佳实践,在WordPress中集成cURL请求,我很想知道。

2ic8powd

2ic8powd1#

首先创建一个包含表单的简单PHP文件,然后发布它。类似于这样:
注意两件事:
1.确保表单中的操作是OK的,并且包含与问题中的示例相同的内容(长URL)。因此,请确保将所有占位符(如{wolkvox_server}})替换为实际正确的值。
1.请确保在HTTP请求中使用令牌添加标头。“wolkvox-token:{{token}}”
然后模仿CURL调用:

<form action="https://wv{{wolkvox_server}}.wolkvox.com/api/v2etcetc" Method="POST">
<input type="text" name="customer_last_name" value="field_3d8268c">
<input type="text" name="customer_id" value="field_d3976af">

etc etc
 <input type="Submit" value="Post me">
</form>

字符串
输入所有POST名称值对:

"customer_name": "namewv",
            "customer_last_name": "field_3d8268c",
            "customer_id": "field_d3976af",
            "city": "field_5dd4679",
            "opt1": "field_9f10881",
            "opt3": "field_6d254ff",
            "opt4": "field_363c904",
            "opt5": "field_a5de87f",
            "opt6": "field_dc05404",
            "opt7": "field_9a9a683",
            "opt8": "field_383d50f",
            "email": "field_8981d35"


它会带回来什么?

相关问题