[英]React fetch gives me a truncated JSON response
我在React fetch中遇到了一個問題,它給了我一個不完整的響應,所以當我將響應解析為JSON時,它給我一個錯誤。
碼:
export default async (url, body = null, method = 'GET') => {
let config = {
method,
};
try {
const response = await fetch(url, config);
if (!response.ok) {
throw new Error(response.statusText);
}
return await response.json();
} catch (error) {
console.warn(error);
throw error;
}
};
fetch是否具有最大響應大小? 如果是,如何增加它?
獲取響應大小沒有最大限制。
您的案例中的錯誤意味着您正在多次閱讀響應正文。 嘗試使用Body.bodyUsed
.json()
調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.