2017-08-05 67 views
1

将数据发送到我的服务器时遇到问题。我的工作与本土反应Axios公司&版本^ 0.16.2用json(body:raw)发送POST数据时总是失败

let input = { 
    'longitude': -6.3922782, 
    'latitude': 106.8268856, 
    'content': 'uget - uget sampai kaki lemes', 
    'pictures': [] 
} 

    axios({ 
    method: 'POST', 
    url, 
    headers: { 
     'Content-Type': 'application/json', 
     'Authorization': this.state.headers.authorization 
    }, 
    data: input 
    })                  
    .then((resultAxios) => { 
    console.log('hasil axios', resultAxios) 
    }) 

和状态结果总是报错500

如果我尝试用邮递员发送数据,一切都很好。在邮差,我把

headers: { 
    Authorization: ''', 
    Content-Type: application/json 
} 

body = raw, JSON 

postman setting

如何才能解决这个问题呢?谢谢:)

+0

任何服务器日志? – msanford

+0

你有没有试过'JSON.stringify(输入)'? – Matthew

+1

很确定上面的评论是解决方案。如果你运行Telerik Fiddler,你可以看到实际的请求,它可能帮助你调试,当它不是你所期望的,并且让你快速看到邮差请求和你自己的差异。 –

回答

0

我发现,爱可信在JSON的身体 在处理一些问题,试试这个:

let input = 'longitude=-6.3922782&latitude=106.8268856&content="uget - uget sampai kaki lemes"&pictures=[]'; 

    axios({ 
    method: 'POST', 
    url, 
    headers: { 
     'Content-Type': 'application/json', 
     'Authorization': this.state.headers.authorization 
    }, 
    data: input 
    })                  
    .then((resultAxios) => { 
    console.log('hasil axios', resultAxios) 
    }) 
and the status result always error 500. 

If I try send data with postman, everything is fine. In postman, I set 

headers: { 
    Authorization: ''', 
    Content-Type: application/json 
} 

body = raw, JSON