返回未定义的提取请求

时间:2018-07-12 17:46:16

标签: html node.js fullcontact

Im试图做的是使用从前端发送的字符串作为检索我所需信息的键。问题部分是让答案,当我使用它时,我收到未定义。但是,例如,如果我改用“ Apple.com”,则提取有效,并且我收到了所需的信息。

到目前为止,我的代码是:

app.post('/todo', function(req, res){

//here we use JSON.stringify to make the object a string
let answer = JSON.stringify(req.body.name);
console.log(answer);

 //here is where we make the api call to get info on the stock
fetch('https://api.fullcontact.com/v3/company.enrich',{
    method: 'POST',
    headers: {
        "Authorization": "Bearer JTm3BBNMqo7xu9PHoG35x8NeohUNfuXl"
    },
    body: JSON.stringify({
        "domain": answer
    })
}).then(function(res) {
    return res.json();
}).then(function(json){
    console.log(json.name);
});

和html代码是这样的:

<form action="/todo" method="POST">
    <input type="text" name="name" class="search" placeholder="todo">
    <button type="submit" id="searchButton">submit</button>
</form>

0 个答案:

没有答案
相关问题