Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using https protocol with REST Client #1

Closed
cbullokles opened this issue Apr 24, 2013 · 3 comments
Closed

Error using https protocol with REST Client #1

cbullokles opened this issue Apr 24, 2013 · 3 comments

Comments

@cbullokles
Copy link

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)

@aacerox
Copy link
Owner

aacerox commented Apr 25, 2013

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 <
notifications@github.com> 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
.

@cbullokles
Copy link
Author

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 <
notifications@github.com> 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 <
notifications@github.com> 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
.

@aacerox
Copy link
Owner

aacerox commented Apr 27, 2013

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.

@aacerox aacerox closed this as completed Apr 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants