以 /__proxy__/fetch 接口为例,展示完整的使用流程。
通过 Base64 编码的 JSON 参数转发复杂请求,支持自定义请求方法、头部等。
{
"url": "https://目标URL", // 必选,目标请求地址
"method": "GET", // 可选,默认 GET,支持 POST/PUT/DELETE 等
"headers": { // 可选,自定义请求头
"Content-Type": "application/json",
"Authorization": "Bearer token"
},
"body": { // 可选,请求体(POST/PUT 等方法使用)
"key": "value"
}
}
{ "url": "https://httpbin.org/post", "method": "POST", "body": { "test": 123 } }
// 原始 JSON 字符串:
'{"url":"https://httpbin.org/post","method":"POST","body":{"test":123}}'
// Base64 编码后(注意:需使用 UTF-8 编码):
'eyJ1cmwiOiJodHRwczovL2h0dHBiaW4ub3JnL3Bvc3QiLCJtZXRob2QiOiJQT1NUIiwiYm9keSI6eyJ0ZXN0IjoxMjN9fQ=='
// 对 Base64 结果执行 encodeURIComponent():
'eyJ1cmwiOiJodHRwczovL2h0dHBiaW4ub3JnL3Bvc3QiLCJtZXRob2QiOiJQT1NUIiwiYm9keSI6eyJ0ZXN0IjoxMjN9fQ%3D%3D'
GET /__proxy__/fetch?arg=eyJ1cmwiOiJodHRwczovL2h0dHBiaW4ub3JnL3Bvc3QiLCJtZXRob2QiOiJQT1NUIiwiYm9keSI6eyJ0ZXN0IjoxMjN9fQ%3D%3D
返回目标 URL 的响应内容(示例为 httpbin.org/post 的返回):
{
"args": {},
"data": "{\"test\":123}",
"files": {},
"form": {},
"headers": {
"Content-Length": "11",
"Content-Type": "application/json",
// ... 其他头信息
},
"json": { "test": 123 },
"origin": "代理服务器 IP",
"url": "https://httpbin.org/post"
}
若参数错误,返回 400 状态码:
{
"title": "Fetch API Error",
"detail": "Invalid Base64 or JSON format"
}