Drupal uses cURLPost to send an object

Source: Internet
Author: User
As we all know, PHP's cURL extension can be used to simulate form submission. in Drupal, there is the drupal_http_request function to execute an HTTP request. it can send a file through POST,

As we all know, PHP's cURL extension can be used to simulate form submission. in Drupal, there is a drupal_http_request function to execute an HTTP request. it can send a file through POST, but it is not as convenient as cURL, here we will mainly explain how to Post a file to a remote server address in Drupal.

The code of Form on the webpage is as follows:

  1.  

The above form contains the submission of the demo text box, password, check box, and file Form. Drupal cURL simulates the form submission of POST, the code is as follows:

  1. $ Url = 'http: // blog.lixiphp.com/demo/http_request/post.php ';
  2. $ Ch = curl_init ();
  3. Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
  4. Curl_setopt ($ ch, CURLOPT_VERBOSE, 0 );
  5. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
  6. Curl_setopt ($ ch, CURLOPT_URL, $ url );
  7. Curl_setopt ($ ch, CURLOPT_POST, true );
  8. $ Post = array (
  9. 'Username' => 'lixip ',
  10. 'Password' => '000000 ′,
  11. 'Rememberme' => '1 ′,
  12. 'Avatar '=>' @ '. $ filename,
  13. );
  14. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );
  15. $ Response = curl_exec ($ ch );
  16. $ Response
The value is the HTML output after the webpage Form is submitted.

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.