简体   繁体   English

Javascript节点请求如何发送GET变量

[英]Javascript Node Request How To Send GET Variables

I see that the request package is the standard for making HTTP API requests with NodeJS. 我看到request包是使用NodeJS发出HTTP API请求的标准。 I need to use it to send some requests but in the docs and all the examples I find, I don't see how to pass GET variables. 我需要使用它来发送一些请求,但是在文档和我找到的所有示例中,我看不到如何传递GET变量。 I only see how to pass POST params. 我只看到如何传递POST参数。 Here's my code: 这是我的代码:

request.get("https://api.example.com", function (err, res, body) {
        if (!err) {
            var resultsObj = JSON.parse(body);
            //Just an example of how to access properties:
            console.log(resultsObj.MRData);
        }
    });

Where to set the GET? 在哪里设置GET? I don't like doing it in the URL. 我不喜欢在URL中这样做。

You're looking for the qs property. 您正在寻找qs属性。 From the docs: 从文档:

qs - object containing querystring values to be appended to the uri qs-包含要附加到uri的querystring值的对象

request({
  qs: {
   foo: 'bar',
  },
  uri: 'http://foo.bar/'
}, callback)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM