spring
spring

Reputation: 18507

How to do a query string with a `ClientRequest`?

(I've been using Electron for a while but haven't had to do any network stuff – so this is a pretty basic question)

The docs for ClientRequest give the example at bottom. I need to pass in a query string like this:

https://someSite.com/edd-sl?edd_action=check_license&item_id=549&license=c0xxxxxx

Is this the correct way to do it (i.e. I cobble together a string "path" - not provide a JSON object, etc.)?

const request = net.request({
  method: 'GET',
  protocol: 'https:',
  hostname: 'someSite.com',
  path: '/edd-sl?edd_action=check_license&item_id=549&license=c0xxxxxx'
})

Electron example

const request = net.request({
  method: 'GET',
  protocol: 'https:',
  hostname: 'github.com',
  port: 443,
  path: '/'
})

Upvotes: 1

Views: 608

Answers (1)

codeandcloud
codeandcloud

Reputation: 55250

Try this.

const querystring = require('querystring');
const params = {
    edd_action: 'check_license',
    item_id: 549,
    license: 'c0xxxxxx'
}
const path = '/edd-sl?' + querystring.stringify(params);

Upvotes: 1

Related Questions