步骤指南
假设你有一个GET要求的URL,如https://www.bjtimes.cc/api?param1=value1¶m2=value2,你可以这样将其转换为POST要求格式:

// 假设这是你的GET要求的URL const url = '//www.bjtimes.cc/api?param1=value1¶m2=value2'; // 解析查询字符串 const paramsString = url.split('?')[1]; // 获取"?"后面的部分 const params = new URLSearchParams(paramsString).entries(); const postBody = Object.fromEntries(params); // 将查询参数转换为工具 // 现在,postBody是一个工具,形如 { param1: 'value1', param2: 'value2' } // 发送POST要求 fetch('http://example.com/api', { method: 'POST', // or 'PUT' if appropriate headers: { 'Content-Type': 'application/json', // 根据你的API哀求设置适当的Content-Type }, body: JSON.stringify(postBody), // 将工具转换为JSON字符串 }) .then(response => response.json()) // 解析相应为JSON .then(data => console.log(data)) // 处理相应数据 .catch(error => console.error('Error:', error)); // 处理缺点