我在快遞服務器上有一個React應用程序。我正在使用fetch從客戶端向服務器發出GET請求,當我在chrome上時響應作為Content-Type text / html返回,而在Postman中嘗試時則返回為application / json。我想要將其作為JSON。郵遞員回應:從按鈕調用時,Chrome中的“網絡”標簽:我嘗試更改快遞請求中的內容類型。app.get('/spotify/search-track', (req,res) => { spotify.searchTrack(req.query.name).then(function(result) { res.setHeader("Content-Type", "application/json"); res.send(result); });});響應GET請求:fetch('/api/spotify/search-tracks?name=' + val, { method: "GET", data: null, headers : { "Accept": "application/json" }}).then(response => response.json()).then(data => console.log(data));我也在Chrome上收到此錯誤-可能是因為<來自HTML。
客戶端到Express服務器中的GET Request僅以text / html形式獲得響應
冉冉說
2021-05-07 14:19:16