Comparing version 0.2.1 to 0.2.2
@@ -103,2 +103,17 @@ var httpreq = require('./httpreq'); | ||
// send your own body content (eg. xml): | ||
httpreq.post('http://posttestserver.com/post.php',{ | ||
body: '<?xml version="1.0" encoding="UTF-8"?>', | ||
headers:{ | ||
'Content-Type': 'text/xml', | ||
}}, | ||
function (err, res) { | ||
if (err){ | ||
console.log(err); | ||
}else{ | ||
console.log(res.body); | ||
} | ||
} | ||
); | ||
@@ -54,3 +54,3 @@ /* | ||
var chunks = []; | ||
var params; | ||
var body; | ||
@@ -71,3 +71,3 @@ var reqUrl = url.parse(o.url); | ||
if(o.method == 'POST' && o.parameters){ | ||
params = querystring.stringify(o.parameters); | ||
body = querystring.stringify(o.parameters); | ||
}else if(o.method == 'GET' && o.parameters){ | ||
@@ -77,2 +77,6 @@ path += "?" + querystring.stringify(o.parameters); | ||
if(o.body){ | ||
body = o.body; | ||
} | ||
var requestoptions = { | ||
@@ -86,7 +90,10 @@ host: reqUrl.hostname, | ||
if(params){ | ||
if(o.method == 'POST' && o.parameters){ | ||
requestoptions['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; | ||
requestoptions['headers']['Content-Length'] = params.length; | ||
} | ||
if(body){ | ||
requestoptions['headers']['Content-Length'] = body.length; | ||
} | ||
if(o.cookies){ | ||
@@ -131,4 +138,4 @@ requestoptions['headers']['Cookie'] = o.cookies.join("; "); | ||
if(params) | ||
request.write(params); | ||
if(body) | ||
request.write(body); | ||
@@ -135,0 +142,0 @@ request.end(); |
{ | ||
"name": "httpreq", | ||
"description": "node-httpreq is a node.js library to do HTTP(S) requests the easy way", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Sam Decrock", |
@@ -21,2 +21,3 @@ node-httpreq | ||
* [Downloading a binary file](#binary) | ||
* [Sending a custom body](#custombody) | ||
@@ -34,2 +35,3 @@ --------------------------------------- | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- body: custom body content you want to send | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -88,2 +90,3 @@ | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- body: custom body content you want to send. Parameters are ignored when this used. | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -183,2 +186,3 @@ | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- body: custom body content you want to send | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -215,2 +219,4 @@ | ||
```js | ||
var httpreq = require('httpreq'); | ||
httpreq.get('https://ssl.gstatic.com/gb/images/k1_a31af7ac.png', {binary: true}, function (err, res){ | ||
@@ -228,2 +234,27 @@ if (err){ | ||
--------------------------------------- | ||
<a name="custombody" /> | ||
### Sending a custom body | ||
Use the body option to send a custom body (eg. an xml post) | ||
__Example__ | ||
```js | ||
var httpreq = require('httpreq'); | ||
httpreq.post('http://posttestserver.com/post.php',{ | ||
body: '<?xml version="1.0" encoding="UTF-8"?>', | ||
headers:{ | ||
'Content-Type': 'text/xml', | ||
}}, | ||
function (err, res) { | ||
if (err){ | ||
console.log(err); | ||
}else{ | ||
console.log(res.body); | ||
} | ||
} | ||
); | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76129
289
255