gpt4 book ai didi

Angular 7 处理大型 post http 请求

转载 作者:搜寻专家 更新时间:2023-10-30 21:44:34 25 4
gpt4 key购买 nike

我有发送大量数据的 post http 请求,并且包含可能非常大的数组。我正在尝试拆分请求,因此我想分块发送,而不是发送一个包含所有数据的请求。

// service.ts
saveRequest(request: AutomationChecklist) {
return this.http
.post(this.url + this.saveRequestUrl, request, this.options)
.map((response: Response) => {
return response.json();
});
}

// automationChecklist.ts
export class AutomationChecklist {
siteInformation: siteInformation;
orderInformation: OrderInformation;
requestInformation: RequestInformation;
contactInformation: ContactInformation;
installations: Installation[]; // save this separately, this one can be quite large
completedAutomation: number;
progress: number;
}

处理此请求的可能解决方案是什么?我读过 forkjoin rxjs 但不确定它是否适合这种情况?

最佳答案

如果你想分离安装,你可以使用concatMapTo操作符来实现:

saveRequest(automations: AutomationChecklist, installations: Installation[]) {
return this.http
.post(this.url + this.saveRequestUrl, automations, this.options)
.pipe(concatMapTo(this.http.post(this.url + /*installations save url*/, installations, this.options)))
.map((response: Response) => {
return response.json();
});
}

这个解决方案的缺点:

  1. 针对同一需求的两个单独请求(创建新的后端端点)
  2. 非原子性:安装请求可能会失败但第一个成功(可能导致结果不一致)
  3. 安装请求等待第一个终止

这取决于你想做什么,如果你接受不一致,这可能是减轻你的要求的一个很好的解决方案。

关于Angular 7 处理大型 post http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57784571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com