c# - c# http请求中的内容类型格式无效
问题描述
我正在尝试设置这样的内容类型:
System.FormatException:'值'multipart/form-data;boundary=ce4da8a9-0e0d-4ba6-9f00-e7f3b002a717'的格式无效。'
执行此操作时
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri)
{
Content = new StringContent(postData, Encoding.UTF8, content_type) // CONTENT-TYPE header
};
但根据这个
https://docs.microsoft.com/en-us/skype-sdk/ucwa/batchingrequests https://ucwa.skype.com/documentation/Resources-batch-3 https://ucwa.skype.com/documentation/编程概念-批处理
所有资源都说使用我拥有的格式。它也没有在 Postman 中抱怨这一点。有没有办法可以StringContent
在 c# 中强制使用这种内容类型?
这里有答案
如何将带有自定义标头的任意 JSON 数据发送到 REST 服务器?
但我不确定如何实现这一点。
解决方案
从错误消息中可以看出答案 s/b。 "multipart/form-data;boundary=ce4da8a9-0e0d-4ba6-9f00-e7f3b002a717"
不是有效的内容类型。即使您正在创建自定义内容类型,也禁止使用以下字符:
( ) @ < > , ; : \ " / [ ] ? = { }
您的内容类型中存在任何这些都会导致
StringContent(postData, Encoding.UTF8, content_type)
失败System.FormatException
推荐阅读
- sfml - SFML 球员运动
- ios - Swift -Countdown Timer with Milliseconds 在 0 处停止,但显示还剩 1 秒
- c# - 我如何让光线投射破坏游戏对象
- java - 有没有办法将泛型类型作为类中的列表?
- laravel - 登录后的中间件
- javascript - 在 JavaScript 中使用“reduce”从另一个数组创建新数组
- ansible - 使用 ansible 在 2 个主机之间同步文件
- java - 未经检查地调用“continueWithTask....”作为原始类型的成员
- javascript - 如何使输入再次可编辑?
- python - 无服务器框架 - Python 和 Requirements.txt - 删除不必要的包