U
U
UntitledNikname2020-04-18 11:44:36
React
UntitledNikname, 2020-04-18 11:44:36

Why does fetch sometimes return a garbled response?

A typical fetch example

fetch("https://api.example.com/items", {"method":"post","body": JSON.stringify(data))
      .then(res => res.json())
      .then(
        (result) => {
        },
        (error) => {
        }
      )

On the locale it returns a normal response like result = "{"a":"b"}" and on the server it adds a header for some reason
and it turns out something like result = "{"a":"b"}{"header":{}}"
Why is this happening? the problem is definitely not in the fetch itself, I tried the same thing through the axios library.
It means something with the response from the server, but the only difference is the http / https protocols

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question