作者:总会有办法的 | 来源:互联网 | 2024-09-30 16:03
1234567891011121314$client = new GuzzleHttp\Client;$respOnse= $client->request('POST', 'http://www.j
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| $client = new GuzzleHttp\Client;
$respOnse= $client->request('POST', 'http://www.jgggbbs.cn/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=LRTTI&inajax=1', array(
'form_params' => array(
'username'=>'test',
'password'=>'fwefwegweg'
),
'allow_redirects' => true,
'headers' => [
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/61.0',
'content-type' => 'application/x-www-form-urlencoded',
'cache-control' => 'no-cache'
]
));
print_r($response->getBody()); //这里输出为空,无法获取到返回结果 |
用PHP GuzzleHttp来登录某个论坛,这里先不管用户名和密码有没有错,也不管提交的参数有没有错,即使有错,网站也会返回出错的文字提示,但是现在我获取不到任何返回的文字,请问是怎么回事呢?
下面是改用php curl来发送这请求,这个能获取到返回结果(同样先不管是否登录成功,只要有返回结果就行):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://www.jgggbbs.cn/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=LRTTI&inajax=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "username=test&password=test",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$respOnse= curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response; //这里能获取反返回结果
} |