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

事情是这样的,使用  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. RH133读书 笔记(5) - Lab 5 User and Group Administration

    Lab 5 User and Group Administration Goal: To build skills for user and group administration. Estimat ...

  2. 更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底

    转载请标明出处:http://blog.csdn.net/android_ls/article/details/39993433 測试的手机IOS系统版本为:6.1.3,实现过程例如以下: 1.加入U ...

  3. iOS中通讯录电话号码空格问题

    今天在读取通讯录的时候,读取到的手机号码格式为* (***) ***-****的,乍看下,数字中间有空格."-".(.)的非数字字符. 然后我就打算替换这些非数字字符,结果替换完, ...

  4. Scala 专题指南

    Scala 专题教程-Case Class和模式匹配 Scala 专题教程-Case Class和模式匹配(1):简单的演示样例 Scala 专题教程-Case Class和模式匹配(2): 模式的种 ...

  5. STL源代码分析--迭代摘要、迭代器失效汇总

    Vector 1.内部数据结构:连续存储,比如数组. 2.随机訪问每一个元素,所须要的时间为常量. 3.在末尾添加或删除元素所需时间与元素数目无关,在中间或开头添加或删除元素所需时间随元素数目呈线性变 ...

  6. js 性能优化整理之 高频优化

    mousemove 拖拽操作 var count = 0; elem.onmousemove = function(){ count++; // 当计数器为偶数的时候不执行mousemove if( ...

  7. jvm在存储区域

    当区域执行的数据  JVM存储器的管理分为几个时间之后的数据区的实施:程序计数器.JavaVM栈.本地方法栈.Java堆.方法区(包括常量池的实现).   程序计数器 较小的内存空间,能够看作是当前线 ...

  8. FastJson基本使用

    在发展中Android的过程中.假设我们常与server联系,更新数据等,然后,json它必须是一个良好的数据格公式,但随着json.使用原生的解析也能够,可是非常不高效,所以这里介绍两种json数据 ...

  9. UVALive - 3263 That Nice Euler Circuit (几何)

    UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit 题意:  给 ...

  10. jsp跳转后台代码页的简易方式~

    jsp跳转到代码隐藏页.有几种方法,例如,: action方式: jquery方式,码如下面: function regCust(){         $('#containerFRM').form( ...