0

我在同一目录中有角度和 dotnet 核心模板应用程序。

我必须在 azure 服务器上上传构建,但出现此错误。请指导我如何解决这个问题。

生产:

ERROR Error: Uncaught (in promise): TR: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":200,"statusText":"OK","url":"https://admin-dev.xperters.com/api/jobs/getJobs","ok":false,"name":"HttpErrorResponse","message":"Http failure during parsing for https://admin-dev.xperters.com/api/jobs/getJobs","error":{"error":{},"text":"<!DOCTYPE html><html lang=\"en\"><head>\n  <meta charset=\"utf-8\">\n  <title>Xperters</title>\n  <base href=\"/\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <link rel=\"icon\" type=\"image/x-icon\" href=\"https://files.xperters.com/images/favicon.webp\">\n  <link href=\"https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css\" rel=\"stylesheet\">\n  <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css\">\n<style>@charset \"UTF-8\";@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500,700);@import url(https://fonts.googleapis.com/earlyaccess/notokufiarabic.css);html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}:after,:before{box-sizing:border-box}html{font-size:10px;-webkit-tap-highlight-color:rgba(0,0,0,0)}body{font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}body,html{margin:0;min-height:100%;height:100%}*{box-sizing:border-box}</style><link rel=\"stylesheet\" href=\"styles.15db04db7ed750153d26.css\" media=\"print\" onload=\"this.media='all'\"><noscript><link rel=\"stylesheet\" href=\"styles.15db04db7ed750153d26.css\"></noscript></head>\n\n<body class=\"dx-viewport\">\n  <app-root></app-root>\n<script src=\"runtime.03132d1f1e3c790b12ce.js\" defer></script><script src=\"polyfills.0087e061b20969056b57.js\" defer></script><script src=\"main.9d0e9744df940a9c2e1d.js\" defer></script>\n\n</body></html>"}}
at G (polyfills.0087e061b20969056b57.js:1)
at polyfills.0087e061b20969056b57.js:1
at Ee (main.9d0e9744df940a9c2e1d.js:1)
at T.invoke (polyfills.0087e061b20969056b57.js:1)
at Object.onInvoke (main.9d0e9744df940a9c2e1d.js:1)
at T.invoke (polyfills.0087e061b20969056b57.js:1)
at I.run (polyfills.0087e061b20969056b57.js:1)
at polyfills.0087e061b20969056b57.js:1
at T.invokeTask (polyfills.0087e061b20969056b57.js:1)
at Object.onInvokeTask (main.9d0e9744df940a9c2e1d.js:1)

本地主机:

ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"https://admin-dev.xperters.com/api/jobs/getJobs","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://admin-dev.xperters.com/api/jobs/getJobs: 0 Unknown Error","error":{"isTrusted":true}}
at resolvePromise (zone.js:1213)
at zone.js:1120
at rejected (index.ts:1)
at ZoneDelegate.invoke (zone.js:372)
at Object.onInvoke (core.js:28692)
at ZoneDelegate.invoke (zone.js:371)
at Zone.run (zone.js:134)
at zone.js:1276
at ZoneDelegate.invokeTask (zone.js:406)
at Object.onInvokeTask (core.js:28679)
4

1 回答 1

1

始终建议提供您正在处理的代码以及您遇到的错误,因为它可以帮助我们重现问题并为您提供解决方案。

所以现在我只能告诉你你可能会遇到这个问题的原因。如下所述,出现此错误有三个可能的原因。请检查所有原因并按照他们解决问题。

  1. 无效的 JSON 格式

    您收到此错误的可能原因之一是您的 JSON 格式不正确。从网络选项卡复制响应并通过JSON 验证器对其进行验证

  2. 错误的响应类型

    另一个原因可能是 HttpClient 默认将响应转换为 response.json()。如果您的 API 返回非 json 响应,您必须指定如下所示。

    return this.http.get/post(url, {responseType: 'text'}).
    
  3. \0 响应中的隐形 字符

    如果您已经在 J​​SON 验证工具中验证了 JSON 并且设置 responseType 没有帮助,请尝试从后端获取 json 并查看是否有任何\0字符。要在 C# 中解决此问题,您可以执行以下操作:

    result.FieldWithStackTrace = result.FieldWithStackTrace?.Replace("\0", string.Empty);
    

我建议您阅读此Angular 文档以获取更多信息。还要检查这个答案和对类似堆栈溢出线程的其他响应。

于 2021-11-23T05:14:40.700 回答