找回密码
 立即注册
首页 程序园 问答 Angular HttpClient 跨二级域名请求问题

Angular HttpClient 跨二级域名请求问题

新程序 3 天前
这次从 angular 15 升级到 angular 17 后遇到的问题,HttpClient 请求的代码如下
  1. downloadImage(imageSrc: string, muteAlert = false): Promise<string | false> {
  2.     return firstValueFrom(
  3.         this.http
  4.             .jsonp<string>(
  5.                 `${uploadApi()}/ImageUploader/DownloadImage?imgSrc=${encodeURIComponent(
  6.                     htmlDecode(imageSrc)
  7.                 )}&app=blog`,
  8.                 'callback'
  9.             )
  10.             .pipe(this.falseOnError(muteAlert))
  11.     );
  12. }
复制代码

angular 应用所用的域名是 i.cnblog.com,HttpClient 请求的域名是 upload.cnblogs.com, 升级之前正常,升级后 HttpClient 请求时没有带 .cnblogs.com 的 cookie

新程序 楼主
3 天前

举报

需要在 app.config.js 中,给 provideHttpClient 加上 withJsonpSupport

  1. provideHttpClient(withJsonpSupport(), withFetch())
复制代码

添加了出现了新的错误

  1. JSONP requests do not support headers
复制代码
您需要登录后才可以回帖 登录 | 立即注册