do-web / curl-request Goto Github PK
View Code? Open in Web Editor NEWcURL Request is a cURL wrapper, support all options and infos from cURL. Use promises, https, http, proxies and more!
License: MIT License
cURL Request is a cURL wrapper, support all options and infos from cURL. Use promises, https, http, proxies and more!
License: MIT License
I like to do this:
curl -F "[email protected]" https://file.io
With this code:
curl.default.verbose = true;
curl
.setHeaders([
'Content-Type: multipart/form-data'
])
.setMultipartBody([{
name: 'filename',
contents: zip_fullpath
}, {
name: 'file',
file: zip_fullpath,
type: 'zip'
}])
.get('https://file.io')
.then(({statusCode, body, headers}) => {
console.log(statusCode, body, headers)
})
.catch((e) => {
console.log('Error: ' + JSON.stringify(e) );
console.log(e);
});
All I get is this error:
* Rebuilt URL to: https://file.io/
document sent to file.io
* Trying 18.205.172.118...
* TCP_NODELAY set
* Connected to file.io (18.205.172.118) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
Error: {}
{}
Hello, how can I set options like CURLOPT_SSL_VERIFYPEER?
Got error while running npm install curl-request --save
node-libcurl ERR! Error: Command failed: node "/Users/dev/Documents/project/node_modules/curl-request/node_modules/node-libcurl/lib/Curl.js"
module.js:471
throw err;
^
Error: Cannot find module 'node-pre-gyp'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/dev/Documents/project/node_modules/curl-request/node_modules/node-libcurl/lib/Curl.js:25:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
I try to use interface option but it doesnt work. No error but gives me other interface's ip
var curl = new (require( 'curl-request' ))();
curl
.setOpt('interface', 'eth0')
.setHeaders([
'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'
])
.get('www.wtfismyip.com/json')
.then(({statusCode, body, headers}) => {
console.log(statusCode,body)
})
.catch((e) => {
console.log(e);
});
It works on command tool with curl. I get the right ip with that command;
sudo curl -s http://www.wtfismyip.com/text --interface eth0
-------------------------------------------------detail error -----------------------------------
Error: Unknown option given. First argument must be the option internal id or the option name. You can use the Curl.option constants.
at Error (native)
at Curl.setOpt (/home/js2/Version2/node_modules/node-libcurl/lib/Curl.js:1004:15)
at module.exports.setOpt (/home/js2/Version2/node_modules/curl-request/index.js:39:19)
at /home/js2/Version2/routes/routes.js:3262:22
at /home/js2/Version2/node_modules/mongoose/lib/query.js:2323:18
at process._tickCallback (internal/process/next_tick.js:103:7)
how to pass setOpt `option?
`const curl = require('curl-request');
var param = {
'device_id': 2325, // Device ID
'module_id': 'dm_bandwidth', // Module ID or name
'period': 'week'
};
var opt = [];
opt = [{'httpheader': 'Content-type: application/json'},{'userpwd':'password'},
{'Curl.option.useragent': 'Ubersmith API Client PHP/1.0'}];
var url = 'https://support.privatelayer.com/api/2.0/?method=device.module_graph';
curl.setHeaders([
'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
'Accept-Encoding: gzip',
'Expect:',
])
curl.setOpt(opt)
.setBody(param)
.get(url)
.then(({ statusCode, body, headers }) => {
console.log("curl", statusCode, "body", body, "header", headers)
res.json({ success: true, deviceDetail: getDeviceDetail[0], devicegraph: body });
})
.catch((e) => {
console.log(e);
});`
Curl has option resolve
How does one use this here, so we don't have to change hosts file?
curl-request not installing, errors occur.
NPM Debug Log File https://ufile.io/b4sg3
Thanks in advanced!
Please help why it happend ?
OS : Centos
NPM : 6.2.0
node : 6.11.3
node-libcurl WARN Could not finish postinstall
node-libcurl ERR! Error: Command failed: node "/home/apps/ardha/project/node_modules/node-libcurl/lib/Curl.js"
module.js:597
return process.dlopen(module, path._makeLong(filename));
^
Error: libcurl-gnutls.so.4: cannot open shared object file: No such file or directory
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/apps/ardha/project/node_modules/node-libcurl/lib/Curl.js:28:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
Thanks
Hello @do-web
How can i send request with proxy that needs authentication?
curl.default.proxy = 'user:password@ip_addr:portno';
OR
curl.default.proxy = 'ip_addr:portno:portno@user:password';
OR
any other thing
Can anyone please guide?
Thanks,
Apoorva Shah
i have error in google cloud function.
Error: Handle already running! at Error (native) at Curl.perform (/user_code/node_modules/curl-request/node_modules/node-libcurl/lib/Curl.js:1051:11) at e (/user_code/node_modules/curl-request/index.js:169:27) at _submit (/user_code/node_modules/curl-request/index.js:141:16) at post (/user_code/node_modules/curl-request/index.js:93:21) at /user_code/index.js:112:9 at f (/user_code/node_modules/@google-cloud/storage/node_modules/once/once.js:25:25) at ConcatStream. (/user_code/node_modules/@google-cloud/storage/node_modules/concat-stream/index.js:37:43) at emitNone (events.js:91:20) at ConcatStream.emit (events.js:185:7)
my code is
/**
exports.getEmail = (event, callback) => {
const file = event.data;
const eventAge = Date.now() - Date.parse(event.timestamp);
const eventMaxAge = 10000;
// Ignore events that are too old
if (eventAge > eventMaxAge) {
console.log(Dropping event ${event} with age ${eventAge} ms.
);
callback();
return;
}
//console.log( Event: ${event.eventId}
);
//console.log( Event Type: ${event.eventType}
);
//console.log( Bucket: ${file.bucket}
);
// console.log( File: ${file.name}
);
//console.log( Metageneration: ${file.metageneration}
);
//console.log( Created: ${file.timeCreated}
);
//console.log( Updated: ${file.updated}
);
if (file.name.match('registerfolder/')) {
storage.
bucket(file.bucket).
file(file.name).
download(function(err, contents) {
var obj = JSON.parse(contents.toString());
curl
.setBody({
'from' : obj.from,
'fromName': obj.sender,
'apikey': process.env.API_KEY,
'subject': obj.subject,
'to': obj.to,
'bodyHtml': obj.text,
'isTransactional': true
})
.post(process.env.API_URL + 'email/send')
.then(({
statusCode,
body,
headers
}) => {
console.log(statusCode, body, headers)
})
.catch((e) => {
console.log(e);
});
});
}
callback();
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.