search

Home  >  Q&A  >  body text

javascript - fetch cannot customize header

fetch(url, {
    method,
    mode: 'cors',
    headers: {
        "Test": "2222"
    }
})
.then(response => response.json())

Interface 404

滿天的星座滿天的星座2779 days ago813

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:49:35

    var headers = new Headers();
    headers.append('Accept', 'application/json'); 
    var request = new Request(URL, {
        headers: headers,
        method:"GET"
    });
    fetch(request).then(function(response) { 
        console.log(response);
     });

    It seems that the headers object is sent, and it seems that your method does not have a value. The 404 is because your url does not exist. Test it with postman first.

    reply
    0
  • Cancelreply