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);