首页 购买软件   代理软件5折优惠 软件更新地址 拼多多类目查询  

获取更新密码关注公众号后回复 更新密码

aria2使用ajax调用

@(文章的标题)

1. 利用ajax调用aria2后台下载

1.1. 总结:

网上很少有的教程ajax调用。

  • aria2作为后台下载服务器,接受前台(浏览器或者cmd命令端口)的命令进行下载。
  • 有了以下ajax命令就可以在网页上点击按钮直接调用aria2后台下载了。

aria2提供网页UI控制界面如Aira2Ng等,直接提供下载地址,提供相关控制下载。
我是对照的http://aria2c.com/以及Aira2Ng请求参数慢慢推敲的,大家也可以这么来获取更多命令。
像什么nodejs已经python也都可以调用,但未深入研究。只觉得ajax调用比较亲民实用,故此研究。并分享出来。

1.2. ajax调用aria2—Demo

自定义工具下载下载地址

1.3. postMan命令测试

postMan能通过也就等于ajax可以使用了,原理一致。需要有前端知识。

1.3.1. post基本使用方法

  1. cmd启动命令可以看日志,窗口关闭失效,
    aria2c.exe –conf-path=aria2.conf
  2. postman请求参数设置
  3. 请求地址http://localhost:6800/jsonrpc
  4. 请求参数如下:(注意post 参数在 body 下 raw下面)

1.3.2. 单一文件下载


测试一:
{
    "jsonrpc": "2.0",
    "method": "aria2.addUri",
    "id": 456,
    "params": [
        ["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
            "split": "5",
            "max-connection-per-server": "5",
            "seed-ratio": "0"
        }
    ]
}

测试二:带下载地址和重命名

{
            "jsonrpc": "2.0",
            "method": "aria2.addUri",
            "id": 1,
            "params": [["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
                "out": "QQ1235.exe",
                "dir": "./微信文件夹",
                "pause": "false",//是否暂停下载
                "split": "5",
                "max-connection-per-server": "5",
                "seed-ratio": "0"
            }]
        }

1.3.3. 取消暂停

[{"jsonrpc":"2.0","method":"aria2.unpause","id":1,"params":["1d02656f3dbbf3a4"]}]

{"jsonrpc":"2.0","method":"aria2.unpause","id":"QXJpYU5nXzE1NzA3MDg1NDZfMC4wNjE0MzE0MTg4Nzc5NDE0Ng==","params":["1d02656f3dbbf3a4"]}

1.3.4. 停止和暂停对应的进程

[{"jsonrpc":"2.0","method":"aria2.pause","id":1,"params":["1d02656f3dbbf3a4"]}]
{"jsonrpc":"2.0","method":"aria2.unpause","id":"1","params":["d9562748f18a4f94"]}

1.3.5. 开始所有/停止所有

{"jsonrpc":"2.0","method":"aria2.pauseAll","id":1,"params":[]}
{"jsonrpc":"2.0","method":"aria2.unpauseAll","id":1,"params":[]}

1.3.6. 查询所有停止下载的信息

{"jsonrpc":"2.0","method":"aria2.tellStopped","id":1,"params":[0,1000]}

1.3.7. 删除记录

{"jsonrpc":"2.0","method":"aria2.removeDownloadResult","id":"QXJpYU5nXzE1NzA3MDk0NjRfMC44OTQ2Njc5NDY0NjQzNTc5","params":["a788bd810e9dcb31"]}

1.3.8. 在下载中强制暂停/停止

{"jsonrpc":"2.0","method":"aria2.forcePause","id":"QXJpYU5nXzE1NzA3MDk4NjdfMC43NDc1OTgzNzkzNDE4NDIx","params":["d9562748f18a4f94"]}

1.3.9. 设置网速

{“lowest-speed-limit”:”1″} 1表示一字节

{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":"QXJpYU5nXzE1NzA3MTAwMDZfMC41MzM4NjkzNjUyMDAzMDE5","params":[{"lowest-speed-limit":"1"}]}

1.3.10. 设置相关参数

{"jsonrpc":"2.0","method":"aria2.changeGlobalOption","id":1,"params":[{"max-overall-download-limit":"1 KiB","max-overall-upload-limit":"20 KiB","max-concurrent-downloads":"20","min-split-size":"10 MiB","user-agent":"Transmission/2.77","dir":"downloadData"}]}

1.3.11. 查看所有正在下载的信息

{"jsonrpc":"2.0","method":"aria2.tellActive","id":1}

返回结果

1.3.12. 查询所有暂时(等待下载信息 非下载完成停止信息)

{"jsonrpc":"2.0","method":"aria2.tellWaiting","id":1,"params":[0,1000]}

1.3.13. 查询所有已经完成或者停止的信息

{"jsonrpc":"2.0","method":"aria2.tellStopped","id":1,"params":[0,1000]}

1.3.14. 查询版本信息

{"jsonrpc":"2.0","method":"aria2.getVersion","id":1,"params":[]}

1.3.15. 查询状态信息

{"jsonrpc":"2.0","method":"aria2.getGlobalStat","id":1,"params":[]}

1.3.16. 获得的多个参数



{
    "jsonrpc": "2.0",
    "method": "aria2.addUri",
    "id": "QXJpYU5nXzE1NzA3MDg5MjZfMC45ODgyODc0NDcxMTE2MzI3",
    "params": [["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe", "http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
        "allow-overwrite": "false",
        "allow-piece-length-change": "false",
        "always-resume": "true",
        "async-dns": "true",
        "auto-file-renaming": "true",
        "bt-enable-hook-after-hash-check": "true",
        "bt-enable-lpd": "false",
        "bt-force-encryption": "false",
        "bt-hash-check-seed": "true",
        "bt-load-saved-metadata": "false",
        "bt-max-peers": "55",
        "bt-metadata-only": "false",
        "bt-min-crypto-level": "plain",
        "bt-remove-unselected-file": "false",
        "bt-request-peer-speed-limit": "51200",
        "bt-require-crypto": "false",
        "bt-save-metadata": "true",
        "bt-seed-unverified": "true",
        "bt-stop-timeout": "0",
        "bt-tracker-connect-timeout": "60",
        "bt-tracker-interval": "0",
        "bt-tracker-timeout": "60",
        "check-integrity": "false",
        "conditional-get": "false",
        "connect-timeout": "60",
        "content-disposition-default-utf8": "false",
        "continue": "true",
        "dir": "./QQ下载文件夹2",
        "dry-run": "false",
        "enable-http-keep-alive": "true",
        "enable-http-pipelining": "false",
        "enable-mmap": "false",
        "enable-peer-exchange": "false",
        "file-allocation": "falloc",
        "follow-metalink": "true",
        "follow-torrent": "true",
        "force-save": "false",
        "ftp-pasv": "true",
        "ftp-reuse-connection": "true",
        "ftp-type": "binary",
        "hash-check-only": "false",
        "http-accept-gzip": "false",
        "http-auth-challenge": "false",
        "http-no-cache": "false",
        "lowest-speed-limit": "0",
        "max-connection-per-server": "5",
        "max-download-limit": "0",
        "max-file-not-found": "0",
        "max-mmap-limit": "9223372036854775807",
        "max-resume-failure-tries": "0",
        "max-tries": "5",
        "max-upload-limit": "0",
        "metalink-enable-unique-protocol": "true",
        "metalink-preferred-protocol": "none",
        "min-split-size": "10485760",
        "no-file-allocation-limit": "5242880",
        "no-netrc": "false",
        "out": "QQ66.exe",
        "parameterized-uri": "false",
        "pause-metadata": "false",
        "piece-length": "1048576",
        "proxy-method": "get",
        "realtime-chunk-checksum": "true",
        "remote-time": "false",
        "remove-control-file": "false",
        "retry-wait": "0",
        "reuse-uri": "true",
        "rpc-save-upload-metadata": "true",
        "save-not-found": "true",
        "seed-ratio": "0",
        "split": "5",
        "stream-piece-selector": "default",
        "timeout": "60",
        "uri-selector": "feedback",
        "use-head": "false",
        "user-agent": "Transmission/2.77"
    }]
}

页面调用


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    </head>
    <body>

    </body>
    <script>
        //https://static.zhihu.com/heifetz/vendor.7177302d6c7d65981005.js
        var url1 = "http://localhost:6800/jsonrpc?tm=1569769711558";
        var downData=[{
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 456,
                "params": [
                    ["http://fastsoft.onlinedown.net/down/PCQQ9.1.8.26211.exe"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }, {
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 457,
                "params": [
                    ["https://cdn.bootcss.com/jquery/3.4.1/jquery.js"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }, {
                "jsonrpc": "2.0",
                "method": "aria2.addUri",
                "id": 458,
                "params": [
                    ["https://static.zhihu.com/heifetz/vendor.7177302d6c7d65981005.js"], {
                        "split": "5",
                        "max-connection-per-server": "5",
                        "seed-ratio": "0"
                    }
                ]
            }];

        $.ajax({
            url: url1,
            data: JSON.stringify(downData),
            type: "post",
            //async: false,//false为同步
            dataType: "json",
            success: function(obj) {
                console.log(obj)
            }
        });
    </script>
</html>
idid

1.4. 相关教程

Aria2 & YAAW 使用说明
下载工具系列——Aria2 (几乎全能的下载神器)

百度Google+研究=知晓一切
也欢迎讨论QQ:1092413979

原文地址:https://www.cnblogs.com/xutaocc/p/11649453.html

码字很辛苦,转载请注明来自QQ相册批量下载器相册批量下载 图片下载工具《aria2使用ajax调用》

评论

评论关闭

备案:吉ICP备13003065号