当我用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