【问题标题】:How do I do a HTTP post request to a secured url?如何向安全 URL 发出 HTTP 发布请求?
【发布时间】:2017-04-04 04:34:11
【问题描述】:

我收到此链接,其中包含 API 参考 http://api.fang88.com/api/we_article/get_all_audited_we_article_ 列表
但是当我点击它时,浏览器说它坏了 给我这个的人说它无法通过浏览器打开,我需要使用空参数对此 url 进行 HTTP 发布请求{}。

我有

var express = require('express');
var app = express();

app.use(express.static(__dirname));

app.get('/', function(req, res){
  res.redirect('/index.html');
});

app.listen(8080);

还有这个json文件

{
  "name": "fang88",
  "version": "1.0.0",
  "authors": [
    "Fang88.com, Inc."
  ],
  "description": "Fang88",
  "keywords": [
    "Fang88",
    "Interview"
  ],
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components"
  ],
  "dependencies": {
    "angular": "~1.6.3"
  }
}

它说如果我打开它,我会得到另一个 json 文件。 我怎样才能使用 javascript 做到这一点?

【问题讨论】:

    标签: javascript json httprequest


    【解决方案1】:

    app.post 告诉 Express JS 监听对 / 的请求,并在看到请求时运行该函数。 当它发布时,会有成功或失败或失败。数据库操作是根据成功或失败进行的。因此,我们提到了错误响应,即在失败时抛出错误并发送带有“记录已更新!”的响应。细绳。 db.Operation.collection.insert

    app.post('/todo', function(req, res) {
      dbOperation.collection('todo').insert(req.body,function(err, result){
        if (err) throw err
        res.send("Record added !");
      })
    })
    

    在 Controller.js 中:

        todo.createTask=function(){      //it is expression for ng-click parameter
      var data = [{                  //as button clicks, the variable data array is declared and with the values of object property.
        name: todo.model.txtTask,
        status:"Pending"
      }];
      $http.post("/todo",data).then(function(response){  //this is $http service shortcut method, used to send the data to specific URL, means it inserts new data based on given URL.
          alert(response.data);
        function(error){
          console.log(error, "Error!");
        })
      }
    

    【讨论】:

    • 请添加更多解释,而不仅仅是代码,以便用户轻松理解。
    • 你能解释一下吗?
    猜你喜欢
    • 1970-01-01
    • 2011-05-19
    • 2018-03-12
    • 2016-01-15
    • 2012-08-31
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    相关资源
    最近更新 更多