PHP curl post request with parameters

Curl is used to communicate with different servers. It also supports different protocols like http, https, ftp, telnet and file protocols for communication. Libcurl also supports HTTPS certificate. I already covered curl get request tutorial in my previous posts but in this tutorial I am going to show you how to use php curl post request with parameters.

PHP CURL POST:

Following are the CURL options we are going to use in curl post request. There are other lots of option which you can use with curl_setopt(). For more details visit php curl_setopt

Option Value
CURLOPT_URL Request URL
CURLOPT_HEADER TRUE to include the header in the output.
CURLOPT_RETURNTRANSFER TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
CURLOPT_CONNECTTIMEOUT The number of seconds to wait while trying to connect. Use 0 to wait indefinitely
CURLOPT_POST TRUE to do a regular HTTP POST. This POST is the normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.
CURLOPT_POSTFIELDS The full data to post in a HTTP “POST” operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ‘;type=mimetype’. This parameter can either be passed as a urlencoded string like ‘para1=val1&para2=val2&…’ or as an array with the field name as key and field data as value.
CURLOPT_SSL_VERIFYPEER FALSE to stop cURL from verifying the peer’s certificate.

 

Posted in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *