php curl curlopt_getfields,php curl之curlopt_postfields参数使用细节

提交表单时,浏览器发送的头部。而 multipart/form-data 知道这是用于上传文件的表单。包括了 boundary 分界符,会多出很多字节。

php手册上这样说:

the full data to post in a http “post” operation. to post a file, prepend a filename with @ and use the full path. this can either be passed as a urlencoded string like ‘para1=val1?2=val2&…' or as an array with the field name as key and field data as value. if value is an array, the content-type header will be set to multipart/form-data.

使用数组提供 post 数据时,curl 组件大概是为了兼容 @filename 这种上传文件的写法,默认把 content_type 设为了 multipart/form-data。

虽然对于大多数服务器并没有影响,但是还是有少部分服务器不兼容。

结论:在没有需要上传文件的情况下,尽量对 post 提交的数据进行 http_build_query 处理,然后再发送出去,能实现更好的兼容性,更小的请求数据包。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值