当我用PHP中的cURL POST文件时,我应该设置CURLOPT_UPLOAD吗? [英] Should I set CURLOPT_UPLOAD when I POST file with cURL in PHP?

查看:1076
本文介绍了当我用PHP中的cURL POST文件时,我应该设置CURLOPT_UPLOAD吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试设置它时,它强制请求方法为PUT。

When I try to set it, it forces the request method to be PUT.

这是我放在CURLOPT_POSTFIELDS:

Here is what I put in CURLOPT_POSTFIELDS:

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'fileUpload' => '@/home/apache/upload/dummy.sql'
));

还是应该忽略CURLOPT_UPLOAD?它说准备文件上传...

Or should I ignore the CURLOPT_UPLOAD at all? It said prepare for file upload...

推荐答案

您可以放心地忽略它。
CURLOPT_POSTFIELDS 足以上传文件。

You can safely ignore it. CURLOPT_POSTFIELDS is just enough to upload a file. The curl library will recognize the file upload and set what's required internally itself.

后面的想法: CURLOPT_UPLOAD 是告诉curl使用 PUT 方法,添加一些常见的文件上传头文件,例如 Expect:100-如果您使用 HTTP / 1.1

The idea behind CURLOPT_UPLOAD is to tell curl to use PUT method, add some common file uploading headers for that such as Expect: 100-continue header and use chunked encoding to upload a file of unknown size if you are using HTTP/1.1

这篇关于当我用PHP中的cURL POST文件时,我应该设置CURLOPT_UPLOAD吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆