【问题标题】:Send array as post in php在php中将数组作为帖子发送
【发布时间】:2017-01-30 22:34:00
【问题描述】:

您好,我有满足以下要求的 api。

这样发送帖子数据:

data[email]  : test@test.com
data[firstName] :first
data[lastName]  : last
data[country]   :DE

如何通过 curl 发送?

【问题讨论】:

标签: php curl post


【解决方案1】:

看到这个答案:How do I use arrays in cURL POST requests

如果你已经有数组 $data:

$field_string = http_build_query($data);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
...

【讨论】:

    猜你喜欢
    • 2011-02-19
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多