Construct a POST request using CURL in php

Source: Internet
Author: User
: This article mainly introduces the use of CURL in php to construct POST requests. For more information about PHP tutorials, see.

Hey, I started my first blog post below. the idea of writing a blog has been around since I started my work, but I have been writing it for a long time, probably because I am lazy.

In recent projects, we need to construct POST requests to transmit data from the backend, so I learned a little bit and want to put this po on the blog. it's better to remember it than to write it down.

Functiontest () {$ url = '/Common/adduser'; // the url you want to request $ data = array ('username' => 'commandid dand ', 'password' => '000000', 'tel' => '000000'); // the data you need to transmit $ ch = curl_init (); // open a handle // set various values curl_setopt ($ ch, CURLOPT_URL, $ url); // Set the URL curl_setopt ($ ch, CURLOPT_POST, 1) to be crawled ); curl_setopt ($ ch, CURLOPT_HEADER, 0); // header information, which is generally false curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); $ result = curl_exec ($ ch); // Obtain the returned value curl_close ($ ch); // Close the handle return $ result ;}

The above code can basically construct POST requests in the background...

Below are some functions in CURL
Curl_close-close a curl session
Curl_copy_handle-copy all content and parameters of a curl connection resource
Curl_errno-a number containing the current session error message is returned.
Curl_error-returns a string containing the current session error message.
Curl_exec-execute a curl session
Curl_getinfo-obtains the information of a curl connection resource handle.
Curl_init-initialize a curl session
Curl_multi_add_handle-add a separate curl handle resource to the curl batch processing session
Curl_multi_close-close a batch processing handle resource
Curl_multi_exec-parse a curl batch handle
Curl_multi_getcontent-return the obtained output text stream
Curl_multi_info_read-obtains the transmission information of the currently resolved curl.
Curl_multi_init-initialize a curl batch processing handle resource
Curl_multi_remove_handle-remove a handle resource from the curl batch processing handle.
Curl_multi_select-Get all the sockets associated with the cURL extension, which can then be "selected"
Curl_setopt_array-set session parameters for a curl in the form of an array
Curl_setopt-set session parameters for a curl
Curl_version-obtain curl-related version information
The function curl_init () initializes a curl session. the unique parameter of the curl_init () function is optional, indicating a url address.
The role of the curl_exec () function is to execute a curl session. the unique parameter is the handle returned by the curl_init () function.
The function curl_close () is used to close a curl session. the only parameter is the handle returned by the curl_init () function.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces the use of CURL in php to construct POST requests, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.