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中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂