Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Axios将尾部斜杠(/)添加到某些URL抓取,但不添加其他URL抓取_Reactjs_Axios - Fatal编程技术网

Reactjs Axios将尾部斜杠(/)添加到某些URL抓取,但不添加其他URL抓取

Reactjs Axios将尾部斜杠(/)添加到某些URL抓取,但不添加其他URL抓取,reactjs,axios,Reactjs,Axios,我正在使用带有React的axios。出于某种原因,在某些回迁上,它随机添加了一个尾随斜杠(/),这会导致我的一些请求无法在服务器上接收 在这个场景中,我注意到了这一点:我有两个连续的抓取 频率限制 详细信息 const urlFrequencyLimits = '/ets/api/general/frequencyLimits'; const urlDetailedUserInfo = '/ets/api/general/getDetailedUserInfo'; // Axios adds

我正在使用带有React的
axios
。出于某种原因,在某些回迁上,它随机添加了一个尾随斜杠(
/
),这会导致我的一些请求无法在服务器上接收

在这个场景中,我注意到了这一点:我有两个连续的抓取

  • 频率限制

  • 详细信息

    const urlFrequencyLimits = '/ets/api/general/frequencyLimits';
    const urlDetailedUserInfo = '/ets/api/general/getDetailedUserInfo'; // Axios adds / here
    try {
        const responseFrequencyLimits = await axios.get(urlFrequencyLimits);
        const responseDetailedUserInfo = await axios.get(urlDetailedUserInfo);
        setFrequencyLimits(responseFrequencyLimits.data);
        setDetailedUserInfo(responseDetailedUserInfo.data);
    }
    
  • Python服务器端URL不需要任何斜杠

    bp = Blueprint('ets', __name__, url_prefix='/ets/api/general')
    @bp.route('/frequencyLimits')
    @bp.route('/getDetailedUserInfo')
    
    开发者工具出错(请注意URL末尾的斜杠)

    问题出在第二次抓取上。第一次抓取看起来完全相同,但其本身工作正常。那么,为什么Axios在这个序列的第二次提取上添加了一个尾随斜杠呢

    Access to XMLHttpRequest at 'http://localhost:5000/ets/api/general/getDetailedUserInfo/' 
    (redirected from 'http://localhost:3000/ets/api/general/getDetailedUserInfo') 
    from origin 'http://localhost:3000' has been blocked by CORS policy: 
    No 'Access-Control-Allow-Origin' header is present on the requested resource.