Skip to content

Commit

Permalink
Better fix for Issue #2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
framingeinstein committed Apr 29, 2013
1 parent eb391f1 commit 04b7927
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 04b7927

Please sign in to comment.