Skip to content
Browse files

Send query string parameters in body for POST requests.

  • Loading branch information...
1 parent 13d9420 commit 23c5c47a8112e331061e43ce96f27ae03ceb3e27 @ammmir committed Apr 3, 2011
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/oauth2.js
View
15 lib/oauth2.js
@@ -36,23 +36,30 @@ exports.OAuth2.prototype._request= function(method, url, headers, access_token,
}
realHeaders['Host']= parsedUrl.host;
- //TODO: Content length should be dynamic when dealing with POST methods....
- realHeaders['Content-Length']= 0;
if( access_token ) {
if( ! parsedUrl.query ) parsedUrl.query= {};
parsedUrl.query["access_token"]= access_token;
}
+ var body;
var result= "";
var options = {
host:parsedUrl.hostname,
port: parsedUrl.port,
- path: parsedUrl.pathname + "?" + querystring.stringify(parsedUrl.query),
method: method,
headers: realHeaders
};
+ if( method == "POST" ) {
+ body = querystring.stringify(parsedUrl.query);
+ options.path = parsedUrl.pathname;
+ } else {
+ options.path = parsedUrl.pathname + "?" + querystring.stringify(parsedUrl.query);
+ }
+
+ options.headers['Content-Length'] = body ? body.length : 0;
+
request = https.request(options, function (response) {
response.addListener("data", function (chunk) {
result+= chunk
@@ -70,7 +77,7 @@ exports.OAuth2.prototype._request= function(method, url, headers, access_token,
callback(e);
});
- request.end();
+ request.end(body);
}

0 comments on commit 23c5c47

Please sign in to comment.
Something went wrong with that request. Please try again.