本文介绍了批处理请求-Dynamics CRM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 全部我正在尝试使用以下源代码向Dynamics CRM实施批处理请求:I am trying to implement a batch request to Dynamics CRM with the following source code:public async Task<HttpResponseMessage> HttpPatchCrmApi(string resource, string data){ string uniq = Guid.NewGuid().ToString(); MultipartContent content = new MultipartContent("mixed", "batch_" + uniq); HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + "/api/data/v8.0/$batch"); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + resource); request.Content = new StringContent(data, Encoding.UTF8, "application/json"); HttpMessageContent query = new HttpMessageContent(request); content.Add(query); batchRequest.Content = content; HttpResponseMessage response = await RbWebApi.SendAsync(batchRequest); return response;}问题是我收到 400错误的请求编辑:如评论中的建议,此处是来自提琴手的请求的堆栈跟踪:As suggested in the comments here is the stack trace of the request from fiddler:POST https://Hidden.api.crm4.dynamics.com/api/data/v8.0/$batch HTTP/1.1Authorization: Bearer eyJ0eXAiOiJKV.... very long stringContent-Type: multipart/mixed; boundary="batch_7b6e3c60-1284-4958-a39a-4653af21833c"Host: Hidden.api.crm4.dynamics.comContent-Length: 313Expect: 100-continue--batch_7b6e3c60-1284-4958-a39a-4653af21833cContent-Type: application/http; msgtype=requestPOST /api/data/v8.0/my_recurringgifts HTTP/1.1Host: Hidden.api.crm4.dynamics.comContent-Type: application/json; charset=utf-8{"my_name":"slavi"}--batch_7b6e3c60-1284-4958-a39a-4653af21833c--在编写代码时,我从此处和此处While writing the code I was inspiring myself from here and here推荐答案我认为您的请求有误。 您必须像那样构建请求正文完全由Microsoft定义I think your request is wrong.You must build the request Body EXACTLY like defined by Microsoft这意味着空白行必须位于正确的位置,所有属性都必须存在于主体中(例如 --changeset_XXX例如,并且我认为您不满足此要求。This means the Blank lines must be there at the right place all the attributes must exist in the body (like "--changeset_XXX" for example) and as I see you dont meet this requirements.我只是在邮递员中针对我的CRM建立了一个Request,它起作用了:I just build a Request in Postman against my CRM and it worked: URLhttps://yourTenant.api.crm.dynamics.com/api/data/v8.0/$batch 标题OData-MaxVersion:4.0OData-Version:4.0Accept:application/jsonAuthorization:Bearer aVeryLongStringTokenHereContent-Type: multipart/mixed;boundary=batch_1234567 身体--batch_1234567Content-Type:multipart/mixed;boundary=changeset_555666--changeset_555666Content-Type:application/httpContent-Transfer-Encoding:binaryContent-ID:1POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1Content-Type:application/json;type=entry{name: 'BatchJobTest788'}--changeset_555666Content-Type:application/httpContent-Transfer-Encoding:binaryContent-ID:2POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1Content-Type:application/json;type=entry{new_name: 'BatchJobTest348'}--changeset_555666----batch_1234567-- 附加说明: 标题的内容类型保存您的BatchId 批次的内容类型保存您的ChangesetId(如果它是更改为数据) 开始编程REST之前调用尝试在像POSTMAN这样的REST工具中定义它们并使它们工作。然后在您的代码中构建工作请求。 此处一个很好的解释说明,用于CRM中的批处理The Content-Type of your Header holds your BatchIdThe Content-Type of your Batch holds your ChangesetId (if it is a change to data)Before starting to programm REST calls try to define them in a REST tool like POSTMAN and make them work. Then build the working request in your code.Here a good explanation-source for the batching in CRM 这篇关于批处理请求-Dynamics CRM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!