GithubHelp home page GithubHelp logo

Comments (3)

aacerox avatar aacerox commented on July 1, 2024

Hi

you don't need to pass the "protocol" as an option to the client. If you
want to call a service through https you just have to use that protocol in
the url, and the client will do the rest of the work for you. ie.:

var Client = require('node-rest-client').Client
var client =new Client();

// call "https" site using the way you prefer between the ones client has

// direct way
client.get("https://remote.site/rest/xml/method", function(data, response){
// parsed response body as js object
console.log(data);
// raw response
console.log(response);
});

If you need to add basic auth to each call just pass username and password
as options to the client, as follow:

var Client = require('node-rest-client');
var auth_options ={
user:"admin",
password:"admin_password"

}

var client = new Client(auth_options);

as you can see in documentation "protocol" is not an allowed option for the
client

Options parameters

You can pass the following args when creating a new client:

var options ={
// proxy configuration
proxy:{
host:"proxy.foo.com", // proxy host
port:8080, // proxy port
user:"ellen", // proxy username if required
password:"ripley" // proxy pass if required
},
user:"admin", // basic http auth username if required
password:"123" // basic http auth password if required};

Hope it helps

On Wed, Apr 24, 2013 at 4:13 AM, Cristian Bullokles <
[email protected]> wrote:

I'm trying to call Client using the next code:

Client = require('node-rest-client').Client;
var options = { protocol: "https"};
var client = new Client(options);

But I'm receiving the error below:
http.js:1604
throw new Error('Protocol:' + options.protocol + ' not supported.');
^
Error: Protocol:https: not supported.
at Object.exports.request (http.js:1604:11)


Reply to this email directly or view it on GitHubhttps://github.com//issues/1
.

from node-rest-client.

cbullokles avatar cbullokles commented on July 1, 2024

That was my first test, without any options... in fact my initial code is:

var sys = require('util');
var Client = require('node-rest-client').Client;

var client = new Client();

var args ={
path:{"apikey":""},
parameters:{lat:xx,lon:xx},
headers:{"test-header":"client-api"}
};

client.get("https://api.forecast.io/forecast/${apikey}/${lat},${lon}", args,
function(data, response){
// parsed response body as js object
console.log(data);
// raw response
console.log(response);
});

http.js:1604
throw new Error('Protocol:' + options.protocol + ' not supported.');
^
Error: Protocol:https: not supported.
at Object.exports.request (http.js:1604:11)
at Object.ConnectManager.normal
(C:\Projects\Sensing\research\node_modules\node-rest-client\lib\node-rest-client.js:273:24)
at Object.exports.Client.Util.connect
(C:\Projects\Sensing\research\node_modules\node-rest-client\lib\node-rest-client.js:131:20)

On Thu, Apr 25, 2013 at 5:43 PM, Alejandro Alvarez Acero <
[email protected]> wrote:

Hi

you don't need to pass the "protocol" as an option to the client. If you
want to call a service through https you just have to use that protocol in
the url, and the client will do the rest of the work for you. ie.:

var Client = require('node-rest-client').Client
var client =new Client();

// call "https" site using the way you prefer between the ones client has

// direct way
client.get("https://remote.site/rest/xml/method", function(data,
response){
// parsed response body as js object
console.log(data);
// raw response
console.log(response);
});

If you need to add basic auth to each call just pass username and password
as options to the client, as follow:

var Client = require('node-rest-client');
var auth_options ={
user:"admin",
password:"admin_password"

}

var client = new Client(auth_options);

as you can see in documentation "protocol" is not an allowed option for
the
client

Options parameters

You can pass the following args when creating a new client:

var options ={
// proxy configuration
proxy:{
host:"proxy.foo.com", // proxy host
port:8080, // proxy port
user:"ellen", // proxy username if required
password:"ripley" // proxy pass if required
},
user:"admin", // basic http auth username if required
password:"123" // basic http auth password if required};

Hope it helps

On Wed, Apr 24, 2013 at 4:13 AM, Cristian Bullokles <
[email protected]> wrote:

I'm trying to call Client using the next code:

Client = require('node-rest-client').Client;
var options = { protocol: "https"};
var client = new Client(options);

But I'm receiving the error below:
http.js:1604
throw new Error('Protocol:' + options.protocol + ' not supported.');
^
Error: Protocol:https: not supported.
at Object.exports.request (http.js:1604:11)


Reply to this email directly or view it on GitHub<
https://github.com/aacerox/node-rest-client/issues/1>
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-17039157
.

from node-rest-client.

aacerox avatar aacerox commented on July 1, 2024

Hi

I've been reviewing the code and you were right. There was a problem with options passed to http/https libs in node.js probably due to a new version of those libs.

Anyway, I've fixed the code (and test it with the url of your example) and publish the update to github and npm as version 0.0.3.

hope now it works for you.

from node-rest-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.