【问题标题】:Nodejs Retrieve the GET query string parametersNodejs 获取 GET 查询字符串参数
【发布时间】:2021-12-23 16:26:02
【问题描述】:

如何更改下面的代码以便进行此查询 (http://localhost:3009/api/get-products/?keywords=underwear) ?我已经尝试了所有能找到的代码 sn-ps ????

app.get("/api/get-products/",async (req, res) => {
 client.execute('aliexpress.affiliate.product.query', {
 'app_signature':'maarifahmall',
 // 'category_ids':'111,222,333',
 'fields':'commission_rate,sale_price',
 'keywords':'beauty',
 'max_sale_price':'100',
 'min_sale_price':'15',
 'page_no':'1',
 'page_size':'50',
 'platform_product_type':'ALL',
 'sort':'SALE_PRICE_ASC',
 'target_currency':'USD',
 'target_language':'EN',
 'tracking_id':'maarifahmall',
 'ship_to_country':'US',
 'delivery_days':'3'
  }, 
 function(error, response) {
 if (!error) {
 res.send(response['resp_result']);
 // ['result']['products']['product']
    } else {
 res.send(error);
    }
  })
});

【问题讨论】:

    标签: node.js reactjs express xmlhttprequest


    【解决方案1】:

    这就是你可以传递路由参数的方式:

    app.get("/api/get-products/:keywords",async (req, res) => {
     client.execute('aliexpress.affiliate.product.query', {
     'app_signature':'maarifahmall',
     // 'category_ids':'111,222,333',
     'fields':'commission_rate,sale_price',
     'keywords':'beauty',
     'max_sale_price':'100',
     'min_sale_price':'15',
     'page_no':'1',
     'page_size':'50',
     'platform_product_type':'ALL',
     'sort':'SALE_PRICE_ASC',
     'target_currency':'USD',
     'target_language':'EN',
     'tracking_id':'maarifahmall',
     'ship_to_country':'US',
     'delivery_days':'3'
      }, 
     function(error, response) {
     if (!error) {
     res.send(response['resp_result']);
     // ['result']['products']['product']
        } else {
     res.send(error);
        }
      })
    });
    

    【讨论】:

    • 我在浏览器中看到“无法获取 /api/get-products/”
    【解决方案2】:

    如果您的意思是如何获取 URL 中的参数值,那么您应该使用req.query,这将产生{ keywords: 'underwear' }。所以你可以使用req.query.keywords来获取keywords的值。

    顺便说一句,您的网址错误,问号前有一个正斜杠。正确的 URL 应该是http://localhost:3009/api/get-products?keywords=underwear

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多