From 04b792766f85f6d97389a435743e951d87134838 Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Mon, 29 Apr 2013 15:10:09 -0400 Subject: [PATCH] Better fix for Issue #2 The last update was a bit hacky. I have found that the root cause russian and other languages was due to an error in the calculation of the content length. The content length is now calculated correctly while continuing to properly encode the post data. --- index.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 6c2108b..2d7aa03 100644 --- a/index.js +++ b/index.js @@ -132,16 +132,7 @@ AlchemyAPI.prototype._doRequest = function(request_query, cb) { }); if(req.method == "POST") { - - /* - Removed this because JSON.stringify was causing issue with unicode characters - //console.log(querystring.stringify(request_query.post)); - */ - if (request_query.post.text) { - req.end("text=" + request_query.post.text); - } else if (request_query.post.html) { - req.end("html=" + request_query.post.text); - } + req.end(querystring.stringify(request_query.post)); } else { req.end(); } @@ -208,9 +199,10 @@ AlchemyAPI.prototype._getQuery = function(data, opts, method) { query.apimethod = "Text" + method; query.post = {text: data}; query.headers = { - 'content-length': '' + data.length + '' - ,'content-type': 'multipart/form-data' + 'content-length': '' + querystring.stringify(query.post).length + '' + ,'content-type': 'application/x-www-form-urlencoded' }; + //console.log(querystring.stringify(query.post).length); //console.log("======================2=================="); } else {