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

事情是这样的,使用  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. [Unity3D] 有关公告板实现的误区

    最直接实现一个公告板,我认为我们应该这样做: usingUnityEngine; publicclassBillboard :MonoBehaviour { voidUpdate() { transf ...

  2. 3、采用Gradle创Libgdx工程

    (原文链接:http://www.libgdx.cn/topic/20/3-%E4%BD%BF%E7%94%A8gradle%E5%88%9B%E5%BB%BAlibgdx%E9%A1%B9%E7%9 ...

  3. 又一次认识HTML,CSS,Javascript 之node-webkit 初探

    今天我们来系统的.全面的 了解一下前端的一些技术,将有助于我们写出 更优秀的 产品 出来. 什么是HTML? HTML 是用来描写叙述网页的一种语言. HTML 包括一些根节点.子节点,文本节点.属性 ...

  4. Chapter 1 Securing Your Server and Network(7):禁用SQL Server Browse

    原文:Chapter 1 Securing Your Server and Network(7):禁用SQL Server Browse 原文出处:http://blog.csdn.net/dba_h ...

  5. TabbedPaneDemo

    package swing.tabbedpane; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import ja ...

  6. 嵌入在网页上Flash媒体播放器(1)

    做的项目,在不久的将来相关的Flash玩家使用,需要播放视频的网页上,不同的视频资源,需要不同的球员.基于使用稳定性.的嵌入式和嵌入式复杂性能的优点概括起来有两种方式(不同的玩家),视频资源也略有不同 ...

  7. nyoj 322 Sort 【树阵】

    这个问题实际上是在测试树的数组. 代码: #include <cstdio> #include <cstring> int c[1005]; int lowbit(int x) ...

  8. SQL Server系统数据库备份最佳实践

    原文:SQL Server系统数据库备份最佳实践 首先了解主要的系统数据库: 系统数据库 master 包含登录信息和其他数据库的核心信息 msdb 存储作业.操作员.警报.备份还原历史.数据库邮件信 ...

  9. error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述

    错误: 1>WinMain.obj : error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述 1> ...

  10. mysql 解压缩和赋权

    拉开拉链mysql紧凑根文件夹 注意ini配置文件的内容 basedir = D:\mysql-5.6.17-winx64  datadir = D:\mysql-5.6.17-winx64  por ...