[Bug] OneDrive 移动/重命名/复制失败:请求体 Content-Type 为 text/plain,Graph 返回 400
Author: lgc2333Created Sep 26, 2026Updated Sep 27, 2026
提交前确认
ZFile 版本
5.0.8(Native 版),另外用 zhaojun1998/zfile:5.0.9-beta4 验证仍有此问题
部署方式
1Panel 应用商店
问题发生在哪些存储源
OneDrive
设备类型
PC
运行环境
与服务端无关:Chrome 140 / Windows 11(抓包确认是服务端发出的请求有问题)
问题复现步骤
- 添加 OneDrive(个人版)存储源,浏览目录、上传、新建文件夹、删除、下载都正常
- 在文件列表选中任意文件或文件夹
- 点「移动」,弹窗里选好目标目录并确认(「重命名」「复制」同理)
- 前端提示「操作失败」/「重命名失败」
预期行为
移动 / 重命名 / 复制成功。
实际行为
100% 失败,zfile 日志只有一条 400,看不到微软的报错原因:
[RestClient] storage=8 | GET https://graph.microsoft.com/v1.0/me/drive/root?select=name,size,lastModifiedDateTime,file,id -> 200
[RestClient] storage=8 | PATCH https://graph.microsoft.com/v1.0/me/drive/root:%2Ffoo%2Fbar.txt -> 400同一存储源的 新建文件夹、删除、上传、下载均正常,只有移动 / 重命名 / 复制失败。
补充信息(根因,抓包确认)
用 -Djavax.net.debug=ssl:plaintext 抓到的真实出站请求(本机另起实例 + 数据库副本,不涉及生产):
PATCH /v1.0/me/drive/root:%2Ffoo%2Fbar.txt HTTP/1.1
Content-Type: text/plain;charset=ISO-8859-1 <-- 问题在这里
Content-Length: 140
{"name":"bar.txt","parentReference":{"id":"<driveId>!<itemId>"},"@microsoft.graph.conflictBehavior":"replace"}
HTTP/1.1 400 Bad Request
{"error":{"code":"BadRequest","message":"Entity only allows writes with a JSON Content-Type header."}}对照同一实例里正常的写操作:
POST /v1.0/me/drive/root:%2Ffoo:/children
Content-Type: application/json <-- 正常
{"folder":{},"@microsoft.graph.conflictBehavior":"replace","name":"test"}
-> 201 Created同一份 body 只改 Content-Type 做 A/B:
| Content-Type | 结果 |
|---|---|
application/json |
200 |
text/plain;charset=ISO-8859-1 |
400 Entity only allows writes with a JSON Content-Type header. |
| 不带 Content-Type | 400 同上 |
受影响的三个操作,都是发 JSON body 但丢掉了 Content-Type:
| 操作 | 请求 | Content-Type | 结果 |
|---|---|---|---|
| 移动 / 重命名 | PATCH .../root:{path} |
text/plain;charset=ISO-8859-1 |
400 |
| 复制 | POST .../root:{path}:/copy |
text/plain;charset=ISO-8859-1 |
400 |
| 新建文件夹 | POST .../root:{path}:/children |
application/json |
201 |
历史日志里 13 次 PATCH 全部 400,没有一次成功;4.x 上同样操作正常。5.0.0 更新日志提到「HTTP 客户端全面重构,自研轻量客户端并移除 Hutool / fastjson 等依赖」,猜测是这次重构后这几处 JSON 请求体没有带上 Content-Type: application/json。
建议修复
移动 / 重命名 / 复制这三处发 JSON body 的请求补上 Content-Type: application/json(照新建文件夹那条路径的写法即可),或在 HTTP 客户端里默认给 JSON 请求体带上正确的 Content-Type。
同时建议:Graph 返回 4xx 时把响应体也记到日志里,现在只记状态码,排查很困难。
Source: zfile-dev/zfile