我们使用下面这两个变量分别做curl post测试:
'apple'];// 字符串$str_data = '{a:apple}';
然后下面是从服务器端打印出来的结果:
上面的图分别从$_server[‘content_type’]、$_post变量、php://input来解析了curlopt_postfields使用数组和字符串的区别。
最后,我们可以得出结论:
1)使用数组的时候
http请求头的content-type会被设置成multipart/form-data;数组内容可以从$_post里面获取;使用file_get_content(“php://input”)为空,对于这一点,php手册上也有说到:
php://input is not available with enctype=”multipart/form-data”
2)使用字符串的时候http请求头的content-type会被设置成application/x-www-form-urlencoded;字符串内容会变成$_post里面的一个元素的key;字符串内容可以完整的从php://input里获取到;版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php curl之curlopt_postfields使用数组和字符串的区别,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。