首页 > Windows下定时GET和POST给特定API数据

Windows下定时GET和POST给特定API数据

服务端API写好了,因为种种原因,需要在Win下写个程序,定时(每20分钟)获取API的数据,然后本地进行一些操作,然后POST操作的数据到服务端。

  1. GET /api/info 返回 {_id: "111", key: "abc", url: "Generating"}

  2. Win本地执行 gen_url.exe --input key --output url

  3. POST /api/info/_id 在body中 {url: "http://a.com"} 就是之前生成的url

请问如何在 Win 下最方便的实现这些功能?因为对于Windows编程不是很熟悉,之前想过:

  1. 写批处理

  2. 写计划任务

  3. 写C#

  4. 写electron

3、4觉得杀鸡用牛刀,1、2不太会,求指点,有什么简单的方法,谢谢!

因为程序是给别人写的,运行在他的win机器上,所以才会考虑越简单约好。现在决定用Node,然后查一下如何调用本地程序,做个最简单的服务器就行了。


lua和nodejs都是很简单快捷的

lua更轻量

nodejs拓展方便(建议用5.1版本,要不回调很麻烦)

{
  "name": "daily",
  "version": "0.0.1",
  "description": "ifttt",
  "main": "node index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "gitai",
  "license": "MIT",
  "dependencies": {
    "co": "^4.6.0",
    "co-request": "^1.0.0",
    "node-schedule": "^0.6.0"
  }
}
schedule.scheduleJob("0 0 8 * * *", dosomething)

上面的0 0 8 *是cron表达式表示每天8点执行

具体使用建议Google相关文档

co和相关模块可以用同步的编写方式在ES6(nodejs5.1默认开启)情况下,写出异步回调

let exec = require('child_process').exec;

exec('git clone https://git.coding.net/dphdjy/Daily.git',function (err, stdout, stderr){
    if (err) {
        console.log(stderr)
    }else{
        post();
        console.log(stdout)
    }
})

写个powershell吧,语法查一查就会了

【热门文章】
【热门文章】