Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (35 sloc) 1.07 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>FE9部 Fetch Demo</title>
</head>
<body>
<h1>Request | FE9部 Fetch Demo</h1>
<div id="fetch">请打开控制面板进行查看</div>
</body>
</html>
<script>
function printHeaders(headers) {
for (let header of headers.entries()) {
console.log(header[0] + ': ' + header[1]);
}
}
</script>
<script>
// 客户端
const headers = new Headers({
'X-Token': 'fe9',
});
const request = new Request('/api/request', {
method: 'GET',
headers,
});
console.log(request); // Request {method: "GET", url: "http://127.0.0.1:4000/api/request", headers: Headers, destination: "", referrer: "about:client", …}
console.log(request.method); // GET
console.log(request.mode); // cors
console.log(request.credentials); // same-origin
// 如果你想打印headers信息,可以调用 printHeaders(request.headers)
</script>