'2',">
时间:2021-07-01 10:21:17 帮助过:5人阅读
$name="进击的巨人";
$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);
代码如下,但是没有获取到搜索这个$name关键词应有的数据,求解?
$name="进击的巨人";
$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);
首先你必须根据抓包数据来确定POST的数据。假设你的POST方式和数据是没有问题的,我只是根据你的代码说出目前的问题。
修改后的代码:
$name="进击的巨人";
$url="http://www.4567.tv/search.asp";
$data = array (
'typeid'=>'2',
'keyword' => mb_convert_encoding($name, "GBK","UTF-8"), //注意这里
);
$data = http_build_query($data);//注意这里
$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);
如果抓包正确,上述代码不能正确执行的话,请根据具体的问题解决,通常可以尝试添加Reffer/UserAgent等信息。
urlencode 去掉
这是接口的请求例子吧?
应该没有什么问题,你把根证书验证关了试一下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);