From 0837ac9be1b62d021e1de3c17912799756b742f5 Mon Sep 17 00:00:00 2001 From: Hanada Date: Sat, 12 Jul 2025 09:44:14 +0800 Subject: [PATCH] Merge pull request #274 from HanadaLee/multipartpostfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构POST内容判断逻辑,去除X-Content-Type标头 --- app/common.php | 30 ++++++++++++++---------------- app/lib/deploy/synology.php | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/common.php b/app/common.php index a1c5e59..861afb1 100644 --- a/app/common.php +++ b/app/common.php @@ -450,25 +450,23 @@ function http_request($url, $data = null, $referer = null, $cookie = null, $head } } } else if (is_array($data) || is_object($data)) { - if (isset($options['headers']['X-Content-Type']) && $options['headers']['X-Content-Type'] == 'multipart/form-data') { + if (!isset($options['headers']['Content-Type'])) { + // 默认为表单 + $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'; + } + if ($options['headers']['Content-Type'] == 'application/x-www-form-urlencoded') { + // 表单 + $options['form_params'] = $data; + } else if ($options['headers']['Content-Type'] == 'multipart/form-data') { // 表单文件 - unset($options['headers']['X-Content-Type']); $options['multipart'] = $data; + unset($options['headers']['Content-Type']); // 由GuzzleHttp重新生成Content-Type头部 + } else if ($options['headers']['Content-Type'] == 'application/json') { + // json + $options['json'] = $data; } else { - if (!isset($options['headers']['Content-Type'])) { - // 默认为表单 - $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'; - } - if ($options['headers']['Content-Type'] == 'application/x-www-form-urlencoded') { - // 表单 - $options['form_params'] = $data; - } else if ($options['headers']['Content-Type'] == 'application/json') { - // json - $options['json'] = $data; - } else { - // 其他 - $options['body'] = http_build_query($data); - } + // 其他 + $options['body'] = http_build_query($data); } } else { $options['body'] = $data; diff --git a/app/lib/deploy/synology.php b/app/lib/deploy/synology.php index f9b3f5c..b0434a8 100644 --- a/app/lib/deploy/synology.php +++ b/app/lib/deploy/synology.php @@ -110,7 +110,7 @@ class synology implements DeployInterface 'SynoToken' => $this->token['synotoken'], ]; $headers = [ - 'X-Content-Type' => 'multipart/form-data' + 'Content-Type' => 'multipart/form-data' ]; $post = [ [