最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Postman response : Could not get any response from server - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a todo-list app and checking it with POSTMAN on every type of request. GET and POST requests are working fine. But PUT and DELETE are not working as expected.

As expected means : It is not showing 404 neither showing results instead it's showing an error, i.e., Could not get any response.

Here's my code of put and delete :

var todos = [];

// DELETE /todos/:id

app.delete('/todos/:id', function(req,res){
    var todoId = parseInt(req.params.id, 10);
    var matchedTodo = _.findWhere(todos, {id: todoId});

    if(!matchedTodo){
        res.status(404).send();
    }else{
        todos = _.without(todos, matchedTodo);
        res.json(matchedTodo);
        //console.log(todos);
    }

});

// PUT /todos/:id

app.put('/todos/:id', function(req,res){

    var todoId = parseInt(req.params.id, 10);
    var matchedTodo = _.findWhere(todos, {id: todoId});
    var body = _.pick(req.body, 'description', 'pleted');
    var validAttributes = {};

    if(!matchedTodo){
        return res.status(404).send();
    }

    if(body.hasOwnProperty('pleted') && _.isBoolean(bodypleted)){
        validAttributespleted = bodypleted;
    }else if(body.hasOwnProperty('pleted')){
        return res.status(400).send();
    }

    if(body.hasOwnProperty('description') && _.isString(body.description) && body.description.trim().length > 0){
        body.description = body.description.trim();
        validAttributes.description = body.description;
    }else if(body.hasOwnProperty('description')){
        return res.status(400).send()
    }

    _.extend(matchedTodo, validAttributes);
    res.json(matchedTodo);



});

Now, I don't know if it's a bug or something.

I'm trying to create a todo-list app and checking it with POSTMAN on every type of request. GET and POST requests are working fine. But PUT and DELETE are not working as expected.

As expected means : It is not showing 404 neither showing results instead it's showing an error, i.e., Could not get any response.

Here's my code of put and delete :

var todos = [];

// DELETE /todos/:id

app.delete('/todos/:id', function(req,res){
    var todoId = parseInt(req.params.id, 10);
    var matchedTodo = _.findWhere(todos, {id: todoId});

    if(!matchedTodo){
        res.status(404).send();
    }else{
        todos = _.without(todos, matchedTodo);
        res.json(matchedTodo);
        //console.log(todos);
    }

});

// PUT /todos/:id

app.put('/todos/:id', function(req,res){

    var todoId = parseInt(req.params.id, 10);
    var matchedTodo = _.findWhere(todos, {id: todoId});
    var body = _.pick(req.body, 'description', 'pleted');
    var validAttributes = {};

    if(!matchedTodo){
        return res.status(404).send();
    }

    if(body.hasOwnProperty('pleted') && _.isBoolean(body.pleted)){
        validAttributes.pleted = body.pleted;
    }else if(body.hasOwnProperty('pleted')){
        return res.status(400).send();
    }

    if(body.hasOwnProperty('description') && _.isString(body.description) && body.description.trim().length > 0){
        body.description = body.description.trim();
        validAttributes.description = body.description;
    }else if(body.hasOwnProperty('description')){
        return res.status(400).send()
    }

    _.extend(matchedTodo, validAttributes);
    res.json(matchedTodo);



});

Now, I don't know if it's a bug or something.

Share Improve this question asked Dec 4, 2015 at 10:31 marukobottomarukobotto 7713 gold badges12 silver badges26 bronze badges 3
  • what does your front end API call look like? edit nevermind that won't matter if you're testing in postman – Luke Schunk Commented Dec 7, 2015 at 3:32
  • are you making sure to pass in an ID into your URL for example localhost:3000/todos/938502 – Luke Schunk Commented Dec 7, 2015 at 3:34
  • Possible duplicate of "Could not get any response" response when using postman with subdomain – Phoenix Commented Oct 9, 2019 at 10:36
Add a ment  | 

1 Answer 1

Reset to default 2

First, you should try the official tips:

  • The server couldn't send a response: Ensure that the backend is working properly
  • Self-signed SSL certificates are being blocked: Fix this by turning off 'SSL certificate verification' in Settings > General
  • Proxy configured incorrectly: Ensure that proxy is configured correctly in Settings > Proxy
  • Request timeout: Change request timeout in Settings > General

Second, normally official tip 2 will solve this problem. If not, you may use environment variables. You should confirm the link (shown in the picture, the protocol) can be accessed.

If not, you should check your environment variable's current value. If the current value is blank, you should fill in and set the options you've changed in official tips to default. And the problem should be solved now.

发布评论

评论列表(0)

  1. 暂无评论