从 9 月 13 日开始,Google Tasks BatchRequest 更新工作流程将在多年来保持稳定的应用程序中触发 400 错误返回“批量请求中的重复请求 ID”。我在请求中找不到任何指示重复请求 ID 的内容。有人知道怎么回事吗?谷歌改变了什么吗?
这是我在发送简单的批处理任务插入请求时收到的响应副本......
[{
"error": {
"code": 400,
"message": "Duplicate Request ID in Batch Request: ",
"errors": [
{
"message": "Duplicate Request ID in Batch Request: ",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}]
UPDATE
在调查这个问题时,我发现 Google 做出了更改,现在需要Content-ID
每个批量请求项上的标头。使用 .Net 时当前未设置此标头Google.Apis.Requests.BatchRequest
class.
为了解决这个问题,我能够创建一个新的 Google.Apis.Requests.BatchRequest 本地实现,并注入一个“Content-ID”标头,然后创建每个请求条目。
private static long _id = 0;
[VisibleForTestOnly]
internal static async Task<HttpContent> CreateIndividualRequest(IClientServiceRequest request)
{
HttpRequestMessage requestMessage = request.CreateRequest(false);
string requestContent = await CreateRequestContentString(requestMessage).ConfigureAwait(false);
var content = new StringContent(requestContent);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/http");
content.Headers.Add("Content-ID", (_id++).ToString());
return content;
}
感谢您解决这个问题!这Content-ID
标题解决了问题。
但不是创建一个新的实现Google.Apis.Requests.BatchRequest
你可以注入一个HttpExecuteInterceptor
进入底层服务,然后由批处理请求调用。
创建拦截器:
public class GoogleBatchInterceptor : IHttpExecuteInterceptor
{
public Task InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Content is not MultipartContent multipartContent)
{
return Task.CompletedTask;
}
foreach (var content in multipartContent)
{
content.Headers.Add("Content-ID", Guid.NewGuid().ToString());
}
return Task.CompletedTask;
}
}
将拦截器添加到服务中:
CalendarService calendarService = CreateTheCalendarService();
calendarService.HttpClient.MessageHandler.AddExecuteInterceptor(new GoogleBatchInterceptor());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)