[Help] php uses curl to simulate post to submit data to obtain the target website information. How can this problem be solved?

Source: Internet
Author: User
The Code is as follows, but no data is obtained to search for the $ name keyword. How can this problem be solved? The {code...} code is as follows, but no data is obtained for searching the $ name keyword. How can this problem be solved?

$ Name = "Attacking giant"; $ url = "http://www.4567. TV /search.asp"; $ data = array ('typeid' => '2 ', 'keyword' => urlencode (mb_convert_encoding ($ name, "GBK", "UTF-8"),); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data ); $ c = curl_exec ($ ch); curl_close ($ ch );

Reply content:

The Code is as follows, but no data is obtained to search for the $ name keyword. How can this problem be solved?

$ Name = "Attacking giant"; $ url = "http://www.4567. TV /search.asp"; $ data = array ('typeid' => '2 ', 'keyword' => urlencode (mb_convert_encoding ($ name, "GBK", "UTF-8"),); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data ); $ c = curl_exec ($ ch); curl_close ($ ch );

First, you must determine the POST data based on the packet capture data. Assume that your POST method and data are correct. I just want to explain the problem based on your code.

Modified code:

$ Name = "Attacking giant"; $ url = "http://www.4567. TV /search.asp"; $ data = array ('typeid' => '2', 'keyword' => mb_convert_encoding ($ name, "GBK", "UTF-8"), // note here); $ data = http_build_query ($ data); // note here $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data ); $ c = curl_exec ($ ch); curl_close ($ ch );

If the packet is captured correctly and the above Code cannot be correctly executed, please solve the problem based on the specific problem. You can usually try to add Reffer/UserAgent and other information.

Remove urlencode

Is this an Interface request example?
There should be no problem. Please turn off the root certificate verification.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

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.