Skip to content

fix content-type error#240

Open
zhaotianff wants to merge 1 commit intoqiniu:masterfrom
zhaotianff:master
Open

fix content-type error#240
zhaotianff wants to merge 1 commit intoqiniu:masterfrom
zhaotianff:master

Conversation

@zhaotianff
Copy link
Copy Markdown

HttpManager类的Post和Get函数会引发异常。

异常信息:

{
  code:0
  
  ref-code:0
  ref-text:
  [2022-10-18 11:23:33.4841] [QiniuCSharpSDK/8.2.0 (UNKNOWN; Win32NT; 6.2.9200.0)] [HTTP-POST] Error:  必须使用适当的属性或方法修改“content-type”标头。
  参数名: name 


}

经过排查,发现是

foreach (string fieldName in headers.Keys)
{
      wReq.Headers.Add(fieldName, headers[fieldName]);
}     

循环头部信息时,Content-Type也在其中
Content-Type不能在头部进行设置,只能通过Content-Type属性设置

系统环境:

  • Windows 10 专业版 1903(18362.295)
  • .Net Framework 4.7.2
  • Visual Studio 2019 Community 16.11.18

@lindexi
Copy link
Copy Markdown

lindexi commented Mar 3, 2026

@zhaotianff 官方好久都没采纳。我刚好最近在用 GPT 翻新我的一个项目,就顺带将这个库也给翻新了,我按照你提供的方法(因为改了 HttpClient 没法直接抄),用成了 TryAddWithoutValidation 规避此问题

详细请看: #268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants