【问题标题】:Why does my HTTP POST response come as an error?为什么我的 HTTP POST 响应出现错误?
【发布时间】:2019-08-11 05:42:28
【问题描述】:

我有一个 Angular 页面,用户在其中选择两个 PDF,然后将它们上传到 API。他们在那里被解析并返回比较的 URL。然后返回的 URL 会显示在 iframe 中。

为了调试,我设置了一个静态返回值“https://google.ch”。

为什么当状态码为 200 时会出现错误?

POST方法:

onSubmit() {
        console.log('Submitted');
        const formModel = this.prepareSave();
        this.loading = true;
        this.http.post('http://localhost:8080/demo', formModel)
            .subscribe(response => {
                console.log(response);
                const returnValue = JSON.stringify(response);
                console.log('parsed: ', returnValue);
                this.comparejobdataService.url = response.toString();
                this.router.navigate(['/draftable']);
            });
        setTimeout(() => {
            this.loading = false;
        }, 10000);
    }

春季启动

@PostMapping("/demo")
    String pdfDiff(@RequestParam("file1") MultipartFile file1, @RequestParam("file2") MultipartFile file2) {
        System.out.println("File 1: " + file1);
        System.out.println("File 2: " + file2);
        return "https://google.ch";
    }

我返回的错误(以图片形式发布,因为结构更易于阅读)

感谢您的任何帮助或建议!

【问题讨论】:

  • JSON.parse: unexpected character - 你期望"https://google.ch"解析为JSON会得到什么?

标签: angular spring-boot post


【解决方案1】:

您收到此错误是因为调用的响应不是有效的 JSON。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-12
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多