栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过cURL传递$ _POST值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过cURL传递$ _POST值

应该工作正常。

$data = array('name' => 'Ross', 'php_master' => true);// You can POST a file by prefixing with an @ (for <input type="file"> fields)$data['file'] = '@/home/user/world.jpg';$handle = curl_init($url);curl_setopt($handle, CURLOPT_POST, true);curl_setopt($handle, CURLOPT_POSTFIELDS, $data);curl_exec($handle);curl_close($handle)

这里有两个选项,

CURLOPT_POST
它们打开HTTP POST,并
CURLOPT_POSTFIELDS
包含要提交的数组数组。可用于向
POST

<form>
s 提交数据。


重要的是要注意,

curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$
data采用两种格式,并且这决定了将如何编码邮政数据。

  1. $data
    as
    array()
    :数据将以
    multipart/form-data
    服务器并不总是接受的方式发送。

    $data = array('name' => 'Ross', 'php_master' => true);

    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);

  2. $data
    作为url编码的字符串:数据将以形式发送
    application/x-www-form-urlenpred
    ,这是提交的html表单数据的默认编码。

    $data = array('name' => 'Ross', 'php_master' => true);

    curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));

我希望这可以帮助其他人节省时间。

看到:

  • curl_init
  • curl_setopt


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433149.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号