Send post or get data using curl

Source: Internet
Author: User

I. Using curl can mimic HTTP requests and send data to the target server or destination IP for operation.

(1). Use PHP to manipulate curl to send a GET request to an interface:

The following is a relatively simple request to write request data, the parameters passed simple violence: (for reference only)

 1   $ch  = curl_init ("/HTTP/ 10.212.0.63/api/changeinfo?action= ".  $action . " &asset= ".  $asset   2  curl_setopt ( $ch , Curlopt_ Returntransfer, 1 3   $rs  = curl_exec ( $ch   4  curl_close ( $ch   5   directly in Curl_init, the parameters that need get past are sent to the receiving end.  6  Note: In this case, it is limited to use the Get method to pass past data, so it is not recommended to use get to transfer data in a way. 

(2). Use PHP to manipulate curl to send a POST request to an interface:

The following is also a relatively simple packaging function, it is recommended to use this method to transfer data, security and transmission of large amounts of data:

1 functionCurl_post ($params){2 3                 $ch=curl_init ();4curl_setopt ($ch, Curlopt_url, "Http://10.212.0.63/Api/ChangeInfo");5curl_setopt ($ch, Curlopt_ssl_verifypeer,false );6curl_setopt ($ch, Curlopt_ssl_verifyhost,false);7                 #curl_setopt ($ch, Curlopt_header, false);8                 #curl_setopt ($ch, Curlopt_httpheader, $header);9curl_setopt ($ch, Curlopt_post,true );Tencurl_setopt ($ch, Curlopt_httpget,false ); Onecurl_setopt ($ch, Curlopt_postfields,$params ); Acurl_setopt ($ch, Curlopt_returntransfer,true ); -  -Curl_exec ($ch); the}
  
Note: An array is passed $params

Two. How to judge the accuracy of the data?

You can use Json_encode () for post or get data on the receiving side, then store it in a file to view the information in the file!

Send post or get data using curl

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.