我想对从 Angular 4 应用程序向 API 项目发出的 POST 和 PUT JSON 请求使用 gzip 或 deflate 压缩。
目前,我正在使用 HttpClient 发送请求。我曾尝试使用 pako 或 zlib 来生成压缩内容,但服务器返回响应指示压缩算法的错误实现。
我的 POST TypeScript 如下所示:
public post(url: string, content: any): Observable < any > {
const fullUrl: string = `${HttpService.baseUrl}/${url}`;
Logger.debug(`Beginning HttpPost invoke to ${fullUrl}`, content);
// Optionally, deflate the input
const toSend: any = HttpService.compressInputIfNeeded(content);
return Observable.create((obs: Observer < any > ) => {
this.client.post(fullUrl, toSend, HttpService.getClientOptions()).subscribe(
(r: any) => {
Logger.debug(`HttpPost operation to ${fullUrl} completed`, r);
// …Run Code Online (Sandbox Code Playgroud)