PHP의 cURL 라이브러리를 사용하여 웹페이지를 크롤링할 때 HTTP 서버에 인증이 필요한 경우가 있습니다. 어떻게 설정해야 하나요?
<?php $url = "http://192.168.0.100:8080/JM-PLATFORM/sms/MobsetSendSMS/sysId/oa/mobileNum/{$mobile_phone}/message/{$message}"; $tmp = sys_get_temp_dir(); $cookieDump = tempnam($tmp, 'cookies'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置存放 Cookie 的文件 curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieDump); //设置 Http 身份验证的方法,这里有多个选项可以选择,可参考 php 手册 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //设置 用户名和密码 curl_setopt($ch, CURLOPT_USERPWD,'User:Password'); $output = curl_exec($ch); curl_close($ch); echo $output; ?>