Dynamics 365 WebApi - BATCH 请求 - 错误 - 消息 header ' ' 无效
Dynamics 365 WebApi - BATCH request - Error - The message header ' ' is invalid
有人在尝试对 Dynamics 365 WebApi 执行 BATCH 请求时遇到以下错误消息吗?我正在使用 Postman。
{
"Message": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionMessage": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionType": "Microsoft.OData.ODataException",
"StackTrace": " at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ValidateHeaderLine(String headerLine, String& headerName, String& headerValue)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ReadHeaders()\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ProcessPartHeader(String& contentId)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReader.SkipToNextPartAndReadHeaders()\r\n at Microsoft.OData.ODataBatchReader.ReadImplementation()\r\n at Microsoft.OData.ODataBatchReader.InterceptException[T](Func`1 action)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsyncImplementationAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<>c__DisplayClass9_0.<<ParseBatchRequestsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.<ExecuteAsync>d__11`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.<ExecuteAsync>d__6`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.OData.Batch.DefaultODataBatchHandler.<ProcessBatchAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Batch.HttpBatchHandler.<SendAsync>d__0.MoveNext()",
"ErrorCode": "0x0"
}
这是我的 Body 内容:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
除了 Batch request unique identifier & headers 之间的额外白线外,没有任何问题,错误可能就是因为这个。删除多余的白线,如下所示:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
我遇到了同样的问题,只是说消息 header '\t'
无效。在我的空白行之一上,我有一个我看不到的制表符。找到并删除后,我的请求就顺利通过了。
有人在尝试对 Dynamics 365 WebApi 执行 BATCH 请求时遇到以下错误消息吗?我正在使用 Postman。
{
"Message": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionMessage": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionType": "Microsoft.OData.ODataException",
"StackTrace": " at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ValidateHeaderLine(String headerLine, String& headerName, String& headerValue)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ReadHeaders()\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ProcessPartHeader(String& contentId)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReader.SkipToNextPartAndReadHeaders()\r\n at Microsoft.OData.ODataBatchReader.ReadImplementation()\r\n at Microsoft.OData.ODataBatchReader.InterceptException[T](Func`1 action)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsyncImplementationAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<>c__DisplayClass9_0.<<ParseBatchRequestsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.<ExecuteAsync>d__11`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.<ExecuteAsync>d__6`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.OData.Batch.DefaultODataBatchHandler.<ProcessBatchAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Batch.HttpBatchHandler.<SendAsync>d__0.MoveNext()",
"ErrorCode": "0x0"
}
这是我的 Body 内容:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
除了 Batch request unique identifier & headers 之间的额外白线外,没有任何问题,错误可能就是因为这个。删除多余的白线,如下所示:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task@odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
我遇到了同样的问题,只是说消息 header '\t'
无效。在我的空白行之一上,我有一个我看不到的制表符。找到并删除后,我的请求就顺利通过了。