Fetch URL
Fetch raw HTTP responses from URLs. Supports multiple URLs and custom headers.
Usage
CODEBLOCK0
Examples
JSON API
CODEBLOCK1
XML
CODEBLOCK2
RSS / Atom Feed
CODEBLOCK3
CSV / Plain Text
CODEBLOCK4
Multiple Formats
CODEBLOCK5
Options
- -
urls_json: JSON array of URLs or a single URL string - INLINECODE1 : Optional JSON array of headers objects (same length as urls)
- INLINECODE2 : Request timeout in milliseconds (default: 30000)
Notes:
- - Returns raw HTTP response body
- For multiple URLs, returns JSON array of results
- Node.js 18+ required (native fetch)
获取URL
从URL获取原始HTTP响应。支持多个URL和自定义请求头。
用法
bash
单个URL
node {baseDir}/scripts/fetch.mjs https://api.example.com/data
多个URL
node {baseDir}/scripts/fetch.mjs [https://api.example.com/data1, https://api.example.com/data2]
带自定义请求头(按URL设置)
node {baseDir}/scripts/fetch.mjs [https://api.example.com/json, https://api.example.com/text] [{accept:application/json}, {accept:text/plain}]
带超时设置
node {baseDir}/scripts/fetch.mjs https://api.example.com/data --timeout 60000
示例
JSON API
bash
GitHub API - 获取仓库信息
node {baseDir}/scripts/fetch.mjs https://api.github.com/repos/microsoft/vscode {accept:application/json,user-agent:Mozilla/5.0}
XML
bash
SOAP服务或XML端点
node {baseDir}/scripts/fetch.mjs https://api.example.com/soap {accept:application/xml}
站点地图
node {baseDir}/scripts/fetch.mjs https://example.com/sitemap.xml
RSS / Atom 订阅源
bash
RSS 2.0 订阅源
node {baseDir}/scripts/fetch.mjs https://example.com/rss.xml {accept:application/rss+xml}
Atom 订阅源
node {baseDir}/scripts/fetch.mjs https://example.com/atom.xml {accept:application/atom+xml}
CSV / 纯文本
bash
CSV数据
node {baseDir}/scripts/fetch.mjs https://example.com/data.csv {accept:text/csv}
纯文本
node {baseDir}/scripts/fetch.mjs https://example.com/robots.txt {accept:text/plain}
多种格式
bash
并行获取JSON和XML
node {baseDir}/scripts/fetch.mjs [https://api.example.com/data.json, https://api.example.com/data.xml] [{accept:application/json}, {accept:application/xml}]
选项
- - urlsjson:URL的JSON数组或单个URL字符串
- headersjson:可选的请求头对象JSON数组(长度需与URL数组一致)
- --timeout <毫秒>:请求超时时间(毫秒,默认值:30000)
注意:
- - 返回原始HTTP响应体
- 对于多个URL,返回结果的JSON数组
- 需要Node.js 18+(原生fetch支持)