完善请求头

This commit is contained in:
杨志
2026-01-20 15:18:09 +08:00
parent 7aa5ce365a
commit 929547657c
3 changed files with 44 additions and 39 deletions

View File

@@ -64,10 +64,19 @@ class Crawler extends BaseController
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8',
'Accept-Encoding: gzip, deflate',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Cookie: ' . $cookieString,
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/',
'Upgrade-Insecure-Requests: 1',
]);
$html = curl_exec($ch);

View File

@@ -29,9 +29,20 @@ class CrawlerService
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie: ' . $cookieString,
'Accept: application/json, text/javascript, */*; q=0.01',
'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8',
'Accept-Encoding: gzip, deflate',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
'Cookie: ' . $cookieString,
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/',
'X-Requested-With: XMLHttpRequest',
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['dsdm' => $dsdm]));
@@ -76,9 +87,20 @@ class CrawlerService
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Cookie: ' . $cookieString,
'Accept: application/json, text/javascript, */*; q=0.01',
'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8',
'Accept-Encoding: gzip, deflate',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
'Cookie: ' . $cookieString,
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/',
'X-Requested-With: XMLHttpRequest',
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([

View File

@@ -246,19 +246,13 @@
<div class="form-group">
<label for="cookie-jsessionid">JSESSIONID</label>
<input type="text" id="cookie-jsessionid" placeholder="示例9E592C9CC752F8552F0D746D91958475">
<small>推荐直接填写避免粘贴JSON出错</small>
<small>从浏览器开发者工具中复制JSESSIONID的值</small>
</div>
<div class="form-group">
<label for="cookie-serverid">SERVERID</label>
<input type="text" id="cookie-serverid" placeholder="示例546762930bd4e5dda968e40edd43fb6a|1768878822|1768878621">
<small>推荐直接填写避免粘贴JSON出错</small>
</div>
<div class="form-group">
<label for="cookies">Cookie数据JSON格式</label>
<textarea id="cookies" placeholder='{"请求 Cookie": {"JSESSIONID": "xxx", "SERVERID": "xxx"}}'></textarea>
<small>可选若上面已填写两个字段此处可留空否则请按JSON格式填写完整Cookie</small>
<small>从浏览器开发者工具中复制SERVERID的值</small>
</div>
<div class="form-group">
@@ -447,42 +441,22 @@
});
}
// 组装Cookie数据支持单独填写和JSON
// 组装Cookie数据
function buildCookiesPayload(messageContainerId) {
const raw = document.getElementById('cookies').value.trim();
const jsessionid = document.getElementById('cookie-jsessionid').value.trim();
const serverid = document.getElementById('cookie-serverid').value.trim();
let cookies = { "请求 Cookie": {} };
if (raw) {
try {
const parsed = JSON.parse(raw);
cookies = parsed;
} catch (e) {
showMessage(messageContainerId, 'Cookie数据格式错误请检查JSON格式', 'error');
return null;
}
}
// 确保存在“请求 Cookie”层级
if (!cookies['请求 Cookie'] || typeof cookies['请求 Cookie'] !== 'object') {
cookies['请求 Cookie'] = {};
}
if (jsessionid) {
cookies['请求 Cookie']['JSESSIONID'] = jsessionid;
}
if (serverid) {
cookies['请求 Cookie']['SERVERID'] = serverid;
}
if (Object.keys(cookies['请求 Cookie']).length === 0) {
showMessage(messageContainerId, '请填写Cookie数据', 'error');
if (!jsessionid || !serverid) {
showMessage(messageContainerId, '请填写JSESSIONID和SERVERID', 'error');
return null;
}
return cookies;
return {
"请求 Cookie": {
"JSESSIONID": jsessionid,
"SERVERID": serverid
}
};
}
// 全选/取消全选