修复:A→B 的 POST 全部无效(JsonContent 不带 Content-Length)
边端是手写的 HTTP 读取,只认 Content-Length;而 A 侧一直用 JsonContent.Create(),它产生的是 chunked 请求 —— 边端把 body 读成空, /check 直接 400,界面就显示「设备管理服务无响应,改由本机校验」。 也就是说局域网共用取流池这条路,用真实客户端从来没成功过, 此前只有 curl 验证过所以一直没暴露。 - EdgeClient 改用 StringContent(显式 Content-Length) - 边端遇到 chunked 请求时明确记一行,不再让调用方看到「空 body」的怪错误 实测:JsonContent → 400 contentLength=null;StringContent → 200 contentLength=186 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
63b70c6ad5
commit
85db722384
@ -602,6 +602,15 @@ public sealed class EdgeHttpService
|
||||
? parsed
|
||||
: 0;
|
||||
|
||||
if (contentLength == 0
|
||||
&& headers.TryGetValue("Transfer-Encoding", out var transferEncoding)
|
||||
&& transferEncoding.Contains("chunked", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// 手写解析只认 Content-Length:真遇到 chunked 就明说,别让调用方看到「空 body」的怪错误
|
||||
AppLog.Write($"[edge] 收到 chunked 请求 {method} {path}(不支持,请用 Content-Length)");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (contentLength is < 0 or > MaxBodyBytes) return null;
|
||||
|
||||
var bodyStart = headerEnd + 4;
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -215,7 +216,13 @@ public sealed class EdgeClient : IDisposable
|
||||
|
||||
if (payload is not null)
|
||||
{
|
||||
request.Content = JsonContent.Create(payload, options: HikWorkerJson.Options);
|
||||
// ⚠️ 不能用 JsonContent.Create:它不带 Content-Length(走 chunked),
|
||||
// 而边端是手写的 HTTP 读取、只认 Content-Length,会把 body 读成空 → 400。
|
||||
// 先用 StringContent 序列化成带长度的请求。
|
||||
request.Content = new StringContent(
|
||||
JsonSerializer.Serialize(payload, HikWorkerJson.Options),
|
||||
Encoding.UTF8,
|
||||
"application/json");
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
<ServerBaseUrl Condition="'$(Configuration)' == 'Debug' and '$(ServerBaseUrl)' == ''">http://127.0.0.1:7300</ServerBaseUrl>
|
||||
<ServerBaseUrl Condition="'$(Configuration)' == 'Release' and '$(ServerBaseUrl)' == ''">https://packs.example.com</ServerBaseUrl>
|
||||
|
||||
<Version>1.0.109</Version>
|
||||
<Version>1.0.110</Version>
|
||||
<Product>浜戜粨瑙嗛婧簮杞欢</Product>
|
||||
<Company>浜戜粨</Company>
|
||||
<AssemblyTitle>浜戜粨瑙嗛婧簮杞欢锛堟湰鏈烘湇鍔★級</AssemblyTitle>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user