4.4保留内容的默认 Content-Type
创建于 2026 年 8 月 17 日约 1 分钟读完
在与一些较老的 HTTP 服务对接时,提交表单数据时不应设置多部分表单内容的 Content-Type,否则可能引发异常。 而现代 HTTP 接口则无此限制。因此,框架默认在提交表单数据时会自动移除多部分表单内容的 Content-Type。
若需取消此操作,可通过以下方式设置:
HttpRequestBuilder.Post("https://furion.net") .SetMultipartContent(multipart => { multipart.OmitContentType = false; // 保留多部分内容默认的 Content-Type // 或使用 multipart.SetOmitContentType(false); });// 【推荐】使用 SetMultipartContent(Action<HttpMultipartFormDataBuilder> configure, bool omitContentType) 重载方法HttpRequestBuilder.Post("https://furion.net/") .SetMultipartContent(multipart => { // ... }, false); // 保留多部分内容默认的 Content-Type