Example of the GET and POST methods called by http in php

Source: Internet
Author: User
The GET and POST methods used are curl_init, curl_setopt, curl_exec, and curl_close. the default function used by the GET method is curl_init, curl_setopt, curl_exec, and curl_close.

The default is the GET method. you can choose whether to use the Header:

$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, "$ url"); curl_setopt ($ ch, CURLOPT_TIMEOUT, 2); curl_setopt ($ ch, CURLOPT_HEADER, 1 ); // if it is set to 0, headercurl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); $ result = curl_exec ($ ch); curl_close ($ ch );

POST method:

$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, '$ URL'); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE ); $ vars = sprintf ('From = % d & to = % d & subject = % s & body = % s', $ from, $ to, urlencode ($ subject ), urlencode ($ body); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ vars); $ ret = curl_exec ($ ch); curl_close ($ ch );

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.