Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPS request with query strings in NodeJS

I am trying to make a request to an API using the get method in the https module.

Looking at HTTPS request in NodeJS, I've got a long way, but my request doesn't appear to include the query parameters…

Using the example from above, with my mods:

var $q = require('q'),
    _ = require('lodash'),
    path = require('path'),
    Qs = require('qs'),
    path = require('path'),
    uuid = require('node-uuid'),
    https = require('https');

var params = {
  schema: '1.0',
  form: 'json',
  username: 'name'
}
var options = {
  host: 'openshift.redhat.com',
  port: 443,
  path: '/broker/rest/api',
  query: params
};

var req = https.get(options, function(res) {
like image 251
mediaashley Avatar asked Jun 01 '16 10:06

mediaashley


People also ask

Can we send query parameters in GET request?

Unless there's something sensitive in the request parameters, it is perfectly fine to send them as part of URL.

Is query string secure in https?

Yes. The entire text of an HTTPS session is secured by SSL. That includes the query and the headers.


1 Answers

According to https://nodejs.org/api/https.html#https_https_request_options_callback there is no option called "query". You need to include the query parameters to the "path".

Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'.

like image 200
n1try Avatar answered Oct 10 '22 04:10

n1try