From 3f3dc74be1bfc49cc959b20765f156fa4a328215 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Wed, 9 Aug 2023 14:50:23 +0800 Subject: [PATCH 1/2] Fixed the wrong request header --- src/routes/Document/components/ApiDebug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/Document/components/ApiDebug.js b/src/routes/Document/components/ApiDebug.js index faab4a5bc..988e38f18 100644 --- a/src/routes/Document/components/ApiDebug.js +++ b/src/routes/Document/components/ApiDebug.js @@ -187,7 +187,7 @@ const FCForm = forwardRef(({ form, onSubmit }, ref) => { const changeParamTab = (key) => { setActiveKey(key); let header = form.getFieldsValue().headers; - let headerJson = {...JSON.parse(header), "Content-type": key === '1' ? "application/json" : "application/x-www-form-urlencoded"}; + let headerJson = {...JSON.parse(header), "Content-Type": key === '1' ? "application/json" : "application/x-www-form-urlencoded"}; setInitialValue({...initialValue, header: JSON.stringify(headerJson)}) } From 5c4f496b72b2b8189312a9c3f3c69c88e26ff490 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Wed, 9 Aug 2023 15:32:38 +0800 Subject: [PATCH 2/2] fixed #310 fixed #310 --- src/routes/Document/components/ApiDebug.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/routes/Document/components/ApiDebug.js b/src/routes/Document/components/ApiDebug.js index faab4a5bc..a049b9a55 100644 --- a/src/routes/Document/components/ApiDebug.js +++ b/src/routes/Document/components/ApiDebug.js @@ -60,6 +60,10 @@ const FCForm = forwardRef(({ form, onSubmit }, ref) => { }); const [activeKey, setActiveKey] = useState("1"); + const getDefaultHeaderByKey = (key) => { + return {"Content-type": key === '1' ? "application/json" : "application/x-www-form-urlencoded"} + } + useEffect( () => { setInitialValue({ @@ -95,7 +99,7 @@ const FCForm = forwardRef(({ form, onSubmit }, ref) => { useEffect( () => { - form.setFieldsValue({headers: initialValue.header || "{}"}) + form.setFieldsValue({headers: initialValue.header || JSON.stringify(getDefaultHeaderByKey(activeKey))}) }, [initialValue.header] ); @@ -187,8 +191,8 @@ const FCForm = forwardRef(({ form, onSubmit }, ref) => { const changeParamTab = (key) => { setActiveKey(key); let header = form.getFieldsValue().headers; - let headerJson = {...JSON.parse(header), "Content-type": key === '1' ? "application/json" : "application/x-www-form-urlencoded"}; - setInitialValue({...initialValue, header: JSON.stringify(headerJson)}) + let headerJson = {...JSON.parse(header), ...getDefaultHeaderByKey(key)}; + setInitialValue({...initialValue, header: JSON.stringify(headerJson)}); } return (