我并不知道问题怎么描述清楚一些。

事情是这样的,使用  Microsoft Dynamics CRM Server 2016 做CRM系统的时候用到 使用 Web API 执行批处理操作(参见SDK或者 https://msdn.microsoft.com/zh-cn/mt607719 ).

官方只给出 相应报文的 文本。告诉你 响应头 怎么写,相应体 怎么写,而我要做的是用c# 实现它。

首先 我使用了 谷歌浏览器 的一个插件,叫 postmen ,第一次听同学说起,还下载错了,下载了 成了 桌面应用程序,其实 是插件。

为啥我用插件呢,因为网站需要登录才能调API啊。需要共享秘钥。

就长这样哈。

然后照着官网的例子,改改就测试通过了。

接下来 就要写 c#代码了。

然后遇到问题了。

不知道怎么 生成Content-Type: multipart/mixed;boundary=changeset_BBB456 !!!

首先尝试了HttpClient  类, DefaultRequestHeaders.TryAddWithoutValidation  方法试了试,不行,位置不对。

StringContent 类试了试 也不行。

最后发现 了 MultipartContent类,果断可以了。

代码如下哈,因为里面有项目封装的一些东西,copy过去 是不能用的哈,意思就这意思。

    public static ApiResult PostBatch()
{
object obj = new object();
string url = "$batch"; var batchUniqueIdHeader = "batch_AAA123";//Guid.NewGuid().ToString(); ICredentials credentials = null; EnsureCredentials(ref credentials);
using (var client = new CRMClient(credentials, null))
{
var data = new
{
neo_phonesysstatus =
};
var multipartContent = new MultipartContent("mixed", "batch_AAA123");
var stringContent = new StringContent(string.Format(@"
--{0}
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1 PATCH http://dev.crm.xiaoniu66.com/DevCRM/api/data/v8.0/neo_marketings(B1D14BC0-2B6B-E611-80C4-005056A97E8D) HTTP/1.1
Content-Type: application/json;type=entry {1} --{0}--
", "changeset_BBB456", data.ToJson()));
stringContent.Headers.Clear();
stringContent.Headers.Add("Content-Type", "multipart/mixed;boundary=batch_AAA123");
multipartContent.Add(stringContent);
HttpResponseMessage response = client.PostAsync(url, multipartContent).Result;
var result = HandleApiResult(response);
return result;
}
}

其中 遇到的几个问题是,要记住 响应头 必须 和 相应体 中间隔着空行。

 

Content-Type boundary 问题的更多相关文章

  1. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundaryRAYPKeHKTYSNdzc1;charset=UTF-8' not supported

    原文:https://www.cnblogs.com/yueli/p/7552888.html 最近同事在做一个图片上传功能.在入参 body 中同时传入文件和其它基本信息结果出现如题异常.在此记录下 ...

  2. the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header

    the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...

  3. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  4. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  5. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  6. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  7. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

  8. Springs Element 'beans' cannot have character [children], because the type's content type is element-only

    Springs Element 'beans' cannot have character [children], because the type's content type is element ...

  9. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  10. .NET获取文件的MIME类型(Content Type)

    第一种:这种获取MIME类型(Content Type)的方法需要在.NET 4.5之后才能够支持,但是非常简单. 优点:方便快捷 缺点:只能在.NET 4.5之后使用 public FileResu ...

随机推荐

  1. 微软研究院的分布式云计算框架orleans

    orleans   Orleans 客户端请求的消息流转以及消息在Silo中再路由机制 Witte 2015-04-29 21:58 阅读:196 评论:0     一种基于Orleans的分布式Id ...

  2. Zen Coding css,html缩写替换大观 快速写出html,css

    阅读本文,先仔细阅读网站文章. Zen Coding 快速编写HTML/CSS代码的实现 复制代码 代码如下:E 元素名称(div, p); E#id 使用id的元素(div#content, p#i ...

  3. 在Linux下,在网络没有配置好前,怎样查看网卡的MAC地址?

    在Linux下,在网络没有配置好前,怎样查看网卡的MAC地址? 使用 dmesg 与 grep 命令来实际,例如以下: [root@localhost ~]# dmesg | grep eth e10 ...

  4. index_ss hint 使用的运行计划变化对照

    index_ss  hint 使用的运行计划变化对照 当中 buffer 代表:当前操作中发生的内存读次数,包括一致性读和当前读 尽管 emp 表记录数不多,可是buffer 读内存的次数区别还是有点 ...

  5. 在Sql中使用Try Catch

    原文:在Sql中使用Try Catch 今天在写sql中出现了!我想在sql使用trycatch吧! 哎..但是语法又记不住了! 那就清楚我们的google大师吧! 嘿,网上关于在sql中使用Try ...

  6. Android应用开发:LoaderManager在Activity/Fragment中的使用分析

    LoaderManager 外部接口initLoader:起始 public <D> Loader<D> initLoader(int id, Bundle args, Loa ...

  7. STL--F - Sequence(n*m-&gt;之前的最低要求m个月)

    F - Sequence Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  8. jQuery EasyUI实现全部关闭tabs

    有时,当我们打开很多tabs当标签,要关闭一个接一个,它只能被关停 显然太麻烦,能够在选项卡的最右边加入一个button 实现关闭所有. 代码例如以下: <!DOCTYPE HTML PUBLI ...

  9. [HA]负载均衡:HAPROXY与KEEPALIVED强强联合

    第一步:更改系统控制配置文件,同意分配虚拟IP(VIP) /etc/sysctl.conf net.ipv4.ip_nonlocal_bind=1 <pre style="word-w ...

  10. lodoop打印控制具体解释

    注意:这就需要引进的打印控制(我上传Demo同时): install_lodop32.exe install_lodop64.exe LodopFuncs.js jquery-1.10.0.min.j ...