[英]Does CURLOPT_POST need to have the number of postfields or just 1/true?
I've seen curl_setopt($ch, CURLOPT_POST, 1);
我看过
curl_setopt($ch, CURLOPT_POST, 1);
mostly written in this way but have noticed that some people express the count()
number of post fields instead of 1
/ true
. 大多数情况下都是以这种方式编写的,但是注意到有些人表示了post字段的
count()
数目,而不是1
/ true
。 Why might they be doing this or could it simply be a misunderstanding of the option? 他们为什么这样做,或者仅仅是对选项的误解?
From the documentation : 从文档中 :
A parameter set to 1 tells libcurl to do a regular HTTP post.
设置为1的参数告诉libcurl进行常规HTTP发布。 This will also make the library use a "Content-Type: application/x-www-form-urlencoded" header.
这也将使库使用“ Content-Type:应用程序/ x-www-form-urlencoded”标头。 (This is by far the most commonly used POST method).
(这是迄今为止最常用的POST方法)。
Seems to me like it's a boolean. 在我看来,这是一个布尔值。 The content-type is enforced for POST requests to be sent properly, which are already default that way in HTML forms that use POST, but not in cURL requests - they have to be set up for it (so this flag is the equivalent of
method="post"
or method="get"
depending on which value you give it, >=1
or 0
respectively. 内容类型是强制执行的,以便可以正确发送POST请求,在使用POST的HTML表单中,默认情况下已经默认了这种类型,但在cURL请求中则不是这种情况-必须为此设置它们(因此,此标志等效于
method="post"
或method="get"
取决于您提供的值,分别为>=1
或0
。
The reason you saw count($data)
in this field in some places is to (in my assumption) disable POST
when the $data
is empty dynamically, so it's 0
when it is empty and >=1
otherwise. 究其原因,你看到的
count($data)
在这个领域中有些地方是(我假设)禁用POST
当$data
是空的动态,所以它的0
时,它是空的, >=1
,否则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.