$mixResponse contains your server response. If HTTP authentication is required, use the below lines.ĬURLOPT_USERPWD => $username. 'Content-Type: application/json', // Only USE this when requesting JSON data $postData = json_encode($arrPostData) // Only USE this when request JSON data. $postData = http_build_query($arrPostData) // Raw PHP array $requestType = 'POST' // This can be PUT or POST It has just one optional parameter: if you pass a string into curlinit (), it will automatically use that string as the URL to work with. I hope this will help others save their time.Ĭurl_setopt($mixCH, $strCurlOpt, $mixCurlOptValue) The curlinit () function returns a Curl instance for us to use in later functions, and you should always store it for later. $data = array('name' => 'Ross', 'php_master' => true) Ĭurl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data)) $data as url encoded string: The data will be sent as application/x-www-form-urlencoded, which is the default encoding for submitted html form data. $data = array('name' => 'Ross', 'php_master' => true) $data as an array(): The data will be sent as multipart/form-data which is not always accepted by the server. It is important to note that curl_setopt($handle, CURLOPT_POSTFIELDS, $data) takes the $data in two formats, and that this determines how the post data will be encoded. This can be used to submit data to POST s. We have two options here, CURLOPT_POST which turns HTTP POST on, and CURLOPT_POSTFIELDS which contains an array of our post data to submit. You can POST a file by prefixing with an (for fields)Ĭurl_setopt($handle, CURLOPT_POST, true) Ĭurl_setopt($handle, CURLOPT_POSTFIELDS, $data)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |