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

事情是这样的,使用  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. Binary System

    Description Usually we use number in the decimal system, for it is so convenient for us to remember ...

  2. 探索Windows Azure 监控和自动伸缩系列2 - 获取虚拟机的监控定义和监控数据

    上一篇博文介绍了如何连接Windows Azure: http://www.cnblogs.com/teld/p/5113063.html 本篇我们继续上次的示例代码,获取虚拟机的监控定义和监控数据. ...

  3. C#软件开发实例.个人定制自己的屏幕抓图工具(八)加入了截图功能键盘

    章文件夹 (一)功能概览 (二)创建项目.注冊热键.显示截图主窗体 (三)托盘图标及菜单的实现 (四)基本截图功能实现 (五)针对拖拽时闪烁卡顿现象的优化 (六)加入配置管理功能 (七)加入放大镜的功 ...

  4. mysql语句中使用like后面的%(百分号)的问题

    问题:mysql语句中使用like后面的%(百分号) 是不是越多运行效率越慢! 总用时:0.0489秒 0.0691 0.0485 0.0467 SELECT `goods_name`, `goods ...

  5. Cocos2dx-3.1.1 冒险01----> 文件夹结构、新项目project创建并执行

    windows开发环境:window7.vs2012.python2.7.6 Cocos2d-x 3.1.1的完整文件夹例如以下:比起曾经的2.x的版本号来说分类更规范了 watermark/2/te ...

  6. 【三】注入框架RoboGuice使用:(Your First Resource Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([二]注入框架RoboGuice使用:(Your First View Injection)),今天我们来看下资源文件的使用注解的方法: 为了在Ac ...

  7. K60 启动过程分析

    很高兴老师借给我一K60的开发板,趁着暑假好好鼓捣鼓捣! 有了上图的过程分析我想心里大概有个低了吧! 以下看代码: /* CodeWarrior ARM Runtime Support Library ...

  8. uva 11572 - Unique Snowflakes(和书略有不同)

    本书是关于使用刘汝佳set, 通过收集找到.count()和删除.erase().这种方法比我好.用较短的时间. 我想map这个任务可以完成.但是,这是不容易删除,必须先找到find()标.然后删除索 ...

  9. KMP该算法解释(最长公共子)

    一个:介绍KMP算法之前,首先解释一下BF算法 (1)BF算法(传统的匹配算法,是最简单的算法) BF算法是一种常见的模式匹配算法,BF该算法的思想是目标字符串S模式串的第一个字符P的第一个字符,以匹 ...

  10. ASP.NET MVC(C#)和Quartz.Net组件

    ASP.NET MVC(C#)和Quartz.Net组件 在之前的文章<推荐一个简单.轻量.功能非常强大的C#/ASP.NET定时任务执行管理器组件–FluentScheduler>和&l ...