douhui4699 2015-07-26 08:51
浏览 106
已采纳

为什么urlencode数据要通过curl发布,为什么不对表单做同样的事情呢?

As stated on php manual urlencode is for encoding query part of url, so why should urlencode be used to encoded data before sending via curl too as these are $_POST values and not query part?

    foreach ($data as $key => $value) {
             $value = urlencode($value);
             $req .= "&$key=$value";
    }
    //
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);

If this is recommended to do, so why this is not necessary to encode posted data via form before processing a submitted form (not for curl, but just processing form I mean.) ?

Does this mean curl is sending data differently than a submitted form does?

  • 写回答

1条回答 默认 最新

  • douxia5179 2015-07-26 09:55
    关注

    You can do:

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    

    instead of the foreach loop. When you give an array, the parameters are posted using multipart/form-data encoding.

    You shouldn't call urldecode in the processing form, because PHP automatically decodes the parameters before putting them into $_GET or $_POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!
  • ¥15 关于#嵌入式硬件#的问题:树莓派第一天重装配置python和opencv后第二天打开就成这样,瞎捣鼓搞出来文件夹还是没把原来的界面调回来
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥100 AT89C52单片机C语言调试之后再回答
  • ¥15 AT89C52单片机C语言串口助手发送数据包返回值
  • ¥15 C++数组中找第二小的数字程序纠错
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)