当前位置: 首页 > 编程语言 > C#

批量请求-DynamicsCRM分享

时间:2023-04-10 18:30:34 C#

批量请求-DynamicsCRM全部,我正在尝试使用以下源代码实现对DynamicsCRM的批量请求:publicasyncTaskHttpPatchCrmApi(stringresource,stringdata){stringuniq=Guid.NewGuid().ToString();MultipartContentcontent=newMultipartContent("mixed","batch_"+uniq);HttpRequestMessagebatchRequest=newHttpRequestMessage(HttpMethod.Post,CrmBaseUrl+"/api/data/v8.0/$batch");HttpRequestMessage请求=newHttpRequestMessage(HttpMethod.Post,CrmBaseUrl+resource);request.Content=newStringContent(data,Encoding.UTF8,"application/json");HttpMessageContentquery=newHttpMessageContent(request.);添加(查询);batchRequest.Content=内容;HttpResponseMessageresponse=awaitRbWebApi.SendAsync(batchRequest);返回响应;}问题是我得到“400Badrequest”/$batchHTTP/1.1授权:BearereyJ0eXAiOiJKV....很长字符串内容类型:多部分/混合;boundary="batch_7b6e3c60-1284-4958-a39a-4653af21833c"主机:Hidden.api.crm4.dynamics.com内容长度:313预期:100-continue--batch_7b6e3c60-1284-4958-a39a-4653af21833c内容类型:应用程序/http;msgtype=requestPOST/api/data/v8.0/my_recurringgiftsHTTP/1.1主机:Hidden.api.crm4.dynamics.com内容类型:application/json;charset=utf-8{"my_name":"slavi"}--batch_7b6e3c60-1284-4958-a39a-4653af21833c--在编写代码时我从这里和这里启发了自己我认为你的要求是错误的你必须喜欢构建Microsoft定义的请求正文,这意味着空行必须位于正确的位置并且所有属性必须出现在文字中(例如“--changeset_XXX”),因为我看到你不符合这个要求。我刚刚在Postman中针对我的CRM构建了一个请求并且它有效:urlhttps://yourTenant.api.crm.dynamics.com/api/data/v8.0/$batchheaderOData-MaxVersion:4.0OData-Version:4.0接受:application/json授权:BeareraVeryLongStringTokenHereContent-Type:multipart/mixed;boundary=batch_1234567body--batch_1234567Content-Type:multipart/mixed;boundary=changeset_555666--changeset_555-666Content:appContent-Transfer-Encoding:binaryContent-ID:1POSThttps://yourTenant.api.crm.dynamics.com/api/data/v8.0/accountsHTTP/1.1Content-Type:application/json;type=entry{name:'BatchJobTest788'}--changeset_555666Content-Type:application/httpContent-Transfer-Encoding:binaryContent-ID:2POSThttps://yourTenant.api.crm.dynamics.com/api/data/v8.0/accountsHTTP/1.1内容-Type:application/json;type=entry{new_name:'BatchJobTest348'}--changeset_555666----batch_1234567--补充说明:以上为C#学习教程:BatchRequest–全部分享给DynamicsCRMContent,如果有对你有用,需要了解更多C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处: