天空小小岛技术论坛

 找回密码
 注册
搜索
查看: 12230|回复: 0
打印 上一主题 下一主题

[总结] curl Post时指定 multipart/form-data 或 application/x-www-form-urlencoded 的方法

[复制链接]
跳转到指定楼层
1#
八号 发表于 2012-2-9 11:58:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_URL, $url);
  3. curl_setopt($ch, CURLOPT_POST, 1);
  4. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  5. curl_exec($ch);
  6. curl_close($ch);
复制代码
如果$data是字符串,则Content-Type是application/x-www-form-urlencoded。

如果$data是k=>v的数组,则Content-Type是multipart/form-data
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|天空小小岛  |京ICP备2025130156号|

GMT+8, 2025-6-21 20:44 , Processed in 0.096240 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表