JS POST 失败,POSTMAN 发成功?-灵析社区

今天吃什么你说吧

JS POST 不执行 `fetch(url` ,直接到 `catch(ex){FR.Logger.error(ex);FR.Msg.toast(FR.i18nText('Custom')+'JS'+FR.i18nText('Error')+' : '+ex.message);}}).createDelegate(this, [], 0).apply(this, arguments)` 代码如下 debugger; const url = 'http://***'; const username = '*****'; const password = '*****'; const Body = { "approver": "N8181820", "factory": "2022", "name_of_parts": "ame_of_parts", "document_number": "NNNNN", "machine_tool_type": "machine_tool_type", "new_version_number": "w_version_nu", "program_name": "program_name", "part_drawing_number": "part_drawin", "auditor": "N8181820", "issuing_nature": "issuing_nature", "list": [ { "sequence_number": "111111111", "field1": "12", "modify_type": "22", "field3": "21321", "field2": "123", "field5": "3213", "field4": "321312" } ], "applicant": "N8181820", "program_number": "ogram_number", "attachment": "attachment", "procedure_description": "edure_descrip", "application_time": "2024-06-23", "machine_number": "machine_numbe", "tzid": "10001", "group_counter": "group_counter", "original_version_number": "ginal_versio", "operation_number": "operation_numbe", "material_code": "material_code" }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa(username + ':' + password) }, body: JSON.stringify(Body) }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok ' + response.statusText); } return response.json(); }) .then(data => { // 处理响应数据 console.log(data); }) .catch(error => { // 处理错误 console.error(error); });

阅读量:145

点赞量:0

问AI
1. 跨域? 2. 跨域包含跨协议、跨端口等 3. fetch 构建请求的过程有问题 4. 你贴的两段代码看起来不是一起的,别的错误也可能会导致直接走 catch