Javascript reactjs app fetch()返回移动html

Javascript reactjs app fetch()返回移动html,javascript,html,reactjs,fetch,Javascript,Html,Reactjs,Fetch,我的react应用程序中的fetch函数返回网站移动版本的html。当我将fetch()与香草JavaScript中的URL一起使用时,我得到了原始的完整桌面html 到目前为止,我已经尝试了以下方法 使用标题:{“用户代理”:“Mozilla/5.0} 使用请求库而不是获取库 我已经厌倦了改变URL,但我还是得到了移动版的html import React,{Component}来自'React'; 导入“/App.css”; 从“react bootstrap”导入{FormGroup,

我的react应用程序中的fetch函数返回网站移动版本的html。当我将
fetch()
与香草JavaScript中的URL一起使用时,我得到了原始的完整桌面html

  • 到目前为止,我已经尝试了以下方法
  • 使用标题:{“用户代理”:“Mozilla/5.0}
  • 使用请求库而不是获取库
  • 我已经厌倦了改变URL,但我还是得到了移动版的html
import React,{Component}来自'React';
导入“/App.css”;
从“react bootstrap”导入{FormGroup,FormControl,InputGroup,Form,}
类应用程序扩展组件{
建造师(道具){
超级(道具)
此.state={
查询:“”,
fimg:[],
}
this.OnSearch=this.OnSearch.bind(this);
}
OnSearch(){
url=”https://www.zerochan.net/Re%3AZero+Kara+Hajimeru+Isekai+Seikatsu?s=fav“
让标题=新标题({
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”,
“用户代理”:“Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/41.0.2272.101 Safari/537.36”
});
获取(url{
标题:标题,
})
。然后(res=>res.text())
。然后(body=>{
控制台日志(正文)
.catch(函数(err){
控制台日志(err);
});
});
}
render(){
返回(
动画形象
在下面输入动画系列的名称
{this.setState({query:event.target.value}}}
onKeyPress={event=>{
如果(event.key=='Enter'){
这个.OnSearch()
}
}
}
/>
this.OnSearch()}>search
{图像}
)
}
导出默认应用程序;

默认情况下,fetch-inside react不会设置cookies,并且当未检测到cookies时,网站将重定向到移动版本

请尝试添加:

  fetch(url, {
      credentials: "same-origin",
      header: headers,
    }).then(...).catch(...);

如果要获取html,为什么要使用application/json?我已经将标题更改为“text/plain”,并且在没有标题代理的情况下,它会返回相同的结果。它获取html,就像我在使用手机一样
  fetch(url, {
      credentials: "same-origin",
      header: headers,
    }).then(...).catch(...);