CURLOPT_POST vs. CURLOPT_POSTFIELDS: Is CURLOPT_POST option required?

前端 未结 2 1200
忘掉有多难
忘掉有多难 2020-12-11 00:11

I\'m new to cURL in PHP. I have a question regarding usage of curl options.

Consider two script files: test1.php and test2.php both present in root

2条回答
  •  無奈伤痛
    2020-12-11 00:56

    You are correct. CURLOPT_POSTFIELDS implies CURLOPT_POST. You don't need to use CURLOPT_POST while using CURLOPT_POSTFIELDS. The request method will always be set to POST in this case.

    Note that this is in your case as long as you want it to be a POST request.

    If you don't want to be it a POST request but set CURLOPT_POSTFIELDS, please see this related Q&A:

    • How to switch from POST to GET in PHP CURL

提交回复
热议问题