代码之家  ›  专栏  ›  技术社区  ›  irqize

无法使用请求模块处理url

  •  0
  • irqize  · 技术社区  · 9 年前

    我正在使用节点中的请求模块从官方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"} 。我认为它不通过星号()的原因是,我应该如何修复它?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Adam Lamers    9 年前

    完全URL编码 market_hash_name 在将其传递给 request 图书馆

    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)
    });