PHP curl post Problems

Source: Internet
Author: User

In A. php, data is submitted to B. php In post mode, but data cannot be received in B. php, And the curl operation is displayed as successful, which is very strange. Originally,"When an array is passed to curlopt_postfields, curl encodes the data into multipart/form-data, and then transmits a URL-encoded string, the data is encoded into application/X-WWW-form-urlencoded.

", While people who are not familiar with curl, like me, often look like the following code when writing a program:

$ DATA = array ('title' => $ title, 'content' => $ content, 'comefrom' => $ comefrom );

Curl_setopt ($ ch, curlopt_dns_use_global_cache, false );

Curl_setopt ($ ch, curlopt_url, 'HTTP: // example.com/ B .php ');

Curl_setopt ($ ch, curlopt_post, 1 );

Curl_setopt ($ ch, curlopt_postfields, $ data );

Curl_exec ($ ch );

That is, the data to be submitted is sent in the form of an array through post, which causes curl to use the "error" encoding "multipart/form-data ", the effect is equivalent to "<form method =" Post "Action =" B. PHP "enctype =" multipart/form-Data ">" to complete the operation. You can try it. PHP "cannot receive data through $ _ post in any way.

Therefore, the correct method should be to change the $ data in the above sample code from an array to URL code () encoded.

 

From http://blog.renren.com/share/246611432/7511385884

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.