PHP Curl进行Post时指定 multipart/form-data 或 application/x-www-form-urlencoded 的方法

先看一段典型的CURL POST的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
curl_close($ch);


这段代码提交出去的Content-Type到底是multipart/form-data还是application/x-www-form-urlencoded呢?我抓包研究了一下,发现Content-Type的类型取决于$data的数据类型。

如果
$data是字符串,则Content-Type是application/x-www-form-urlencoded。

如果
$data是k=>v的数组,则Content-Type是multipart/form-data

相关文章:

  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2021-07-18
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案