无法使用请求模块处理 url

Can't process url with request module

本文关键字:模块 处理 url 请求      更新时间:2023-09-26

我正在使用节点中的请求模块从官方API下载Steam项目的价格.js(http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=),它工作得很好,除了名称以星号()★开头的项目,然后url看起来由节点处理http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=★%20M9%20Bayonet%20%7C%20Stained%20(Field-Tested)。当手动输入它到浏览器时,它运行良好,但是当我的 Steam 机器人执行此操作时,Steam 返回 {"success":"false"} .我认为它没有通过星号符号(★)的原因,我应该如何解决它?

在将market_hash_name传递到request库之前对其进行完全 URL化编码。

request = require("request")
request("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=%e2%98%85+M9+Bayonet+%7c+Stained+(Field-Tested)", function(e, response, body) {
    console.log(body)
});