简体   繁体   English

axios(react) 和 express 出现 404 错误

[英]there is 404 error with axios(react) and express

this is my react code这是我的反应代码

 <button type='submit' onClick={()=>{axios.get('https://eccwithnodejs.df.r.appspot.com:443/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response)
    });}} >버튼</button>

and these are my node js code with express这些是我的 node js 代码与 express

this is create server code这是创建服务器代码

    var server=http.createServer(app).listen(8080,function(){
        console.log('succesful');
    })
    
    https.createServer(options,app).listen(443,function(){
        console.log('succesful https');
    })

this is get method这是获取方法

app.get('https://eccwithnodejs.df.r.appspot.com:443/user',function(req,res){
var tempUser={"name":"asd",
"birth":970204,
"email":"으헤헤헤이거슨이메일",
"uid":"유니크다음은 전설"
}

res.send(tempUser);
console.log(tempUser);
})

and I got errorcode 404 like this我得到了这样的错误代码404

{data: '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta char…ody>\n<pre>Cannot GET /user</pre>\n</body>\n</html>\n', status: 404, statusText: '', headers: {…}, config: {…}, …}

What is the problem?问题是什么? please help... :(请帮忙... :(

In your get method, you also need to mention the endpoint not full domain name.在您的 get 方法中,您还需要提及端点而不是完整的域名。 So, remove your domain name from the get method.因此,请从 get 方法中删除您的域名。

app.get(/user',function(req,res){
var tempUser={"name":"asd",
"birth":970204,
"email":"으헤헤헤이거슨이메일",
"uid":"유니크다음은 전설"
}

now change your react code.现在更改您的反应代码。

<button type='submit' onClick={()=>{axios.get('https://<<your_domain>>:8080/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response)
    });}} >버튼</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM