FAQ
Hello,

I'm trying to use HTTP module for communicating with chromedriver. Not a
quite common use case, of course... Surprisingly, even when the all the
parts are reliable, they do not work together.

Here are the steps to reproduce:

1. Download chromedriver test and unpack it

http://code.google.com/p/chromedriver/downloads/detail?name=chromedriver_test.zip
2. Run the run_test.bat file from the test
it only runs chromedriver.exe and use wget to sent the request to the
driver as follows:
wget\wget.exe http://127.0.0.1:33791/session --post-file=new_session.txt
the new_session.txt file contains the following string:
{ "desiredCapabilities": {}}
It works well.
3. I've created a simple node.js file with the following content:
var data = '{ "desiredCapabilities": {}}',
req = require('http').request(
{ host : '127.0.0.1', port : 33791, method : 'POST',
path : '/session', headers : {
'Content-length' : data.length,
'Accept' : '*/*',
'Content-type' : 'application/x-www-form-urlencoded'
}
},
function (res) {
console.log('DEBUG STATUS: ' + res.statusCode);
console.log('DEBUG HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
}
);
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end(data);

It is supposed to do exactly the same that the wget in the chromedriver
test does. But it does not - the driver returns
DEBUG STATUS: 400
DEBUG HEADERS: {"content-length":"77","content-type":"application/json;
charset=utf-8"}
{"status":400,"value":{"message":"Missing or invalid
'desiredCapabilities'"}}
instead of opening new chrome window.

Maybe you have the ideas on what's going on?

Node version: 0.6.17

Thanks,
Alex



--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Mscdex at May 12, 2012 at 1:11 am

    On May 11, 8:45 pm, Alex Netkachov wrote:
    'Content-length' : data.length,
    Just out of curiousity, instead of `data.length` here, try
    `Buffer.byteLength(data)` and see how that goes.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Alex Netkachov at May 12, 2012 at 1:21 am

    On Saturday, May 12, 2012 4:11:30 AM UTC+3, mscdex wrote:
    On May 11, 8:45 pm, Alex Netkachov wrote:
    'Content-length' : data.length,
    Just out of curiousity, instead of `data.length` here, try
    `Buffer.byteLength(data)` and see how that goes.

    The same. I've created a small script that dumps the request:

    var http = require('http'), fs = require('fs');
    http.createServer(function (req, res) {
    var stream = fs.createWriteStream('requests.log', {flags: 'a',
    encoding: 'utf8'});
    stream.write('Request info:\n');
    stream.write(' URL: ' + req.url + '\n');
    stream.write(' Method: ' + req.method + '\n');
    stream.write(' Headers:\n');
    Object.keys(req.headers).forEach(function (header) {
    stream.write(' ' + header + ': ' + this[header] + '\n');
    }, req.headers);
    req.on('data', function (chunk) {
    stream.write(' Data: ' + chunk + '\n');
    });
    req.on('end', function () {
    stream.end();
    });

    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('okay');
    }).listen(33791, '127.0.0.1');

    and it dumps almost the same for both requests:

    Request info:
    URL: /session
    Method: POST
    Headers:
    content-length: 28
    accept: */*
    content-type: application/x-www-form-urlencoded
    host: 127.0.0.1:33791
    connection: keep-alive
    Data: { "desiredCapabilities": {}}
    Request info:
    URL: /session
    Method: POST
    Headers:
    user-agent: Wget/1.11.4
    accept: */*
    host: 127.0.0.1:33791
    connection: Keep-Alive
    content-type: application/x-www-form-urlencoded
    content-length: 28
    Data: { "desiredCapabilities": {}}

    content-length is the same. I've added User-agent so they become identical
    - no success.

    Thanks,

    Alex

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Alex Netkachov at May 12, 2012 at 10:11 am
    Success!

    ChromeDriver accepts "Content-Length" in headers and does not accept
    "Content-length". So the following code works:

    var data = '{ "desiredCapabilities": {}}',
    req = require('http').request(
    { host : '127.0.0.1', port : 33791, method : 'POST',
    path : '/session', headers : {
    'Content-Type' : 'application/json;charset=UTF-8',
    'Content-Length' : data.length
    }
    },
    function (res) {
    console.log('DEBUG STATUS: ' + res.statusCode);
    console.log('DEBUG HEADERS: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    console.log(chunk);
    });
    }
    );
    req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
    });
    req.end(data);

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Isaac Schlueter at May 12, 2012 at 4:00 pm
    Looks like ChromeDriver has a bug. HTTP headers are case-insensitive
    according to the specification.

    On Sat, May 12, 2012 at 3:11 AM, Alex Netkachov
    wrote:
    Success!

    ChromeDriver accepts "Content-Length" in headers and does not accept
    "Content-length". So the following code works:

    var data = '{ "desiredCapabilities": {}}',
    req = require('http').request(
    { host : '127.0.0.1', port : 33791, method : 'POST',
    path : '/session', headers : {
    'Content-Type' : 'application/json;charset=UTF-8',
    'Content-Length' : data.length
    }
    },
    function (res) {
    console.log('DEBUG STATUS: ' + res.statusCode);
    console.log('DEBUG HEADERS: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    console.log(chunk);
    });
    }
    );
    req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
    });
    req.end(data);

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedMay 12, '12 at 12:46a
activeMay 12, '12 at 4:00p
posts5
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase