Answer the question
In order to leave comments, you need to log in
Where is the error in CURL? Why is the image not loading?
Here's the full code
. I'm trying to download a picture from a toaster and save it to a file.
It doesn't matter where to save it, even if you create a server and try to display it on the screen, nothing comes out.
Where is the mistake?
Or is it just a curl curve?
9050 is a torus port
//https://github.com/JCMais/node-libcurl
var Curl = require('node-libcurl').Curl,
path = require('path'),
fs = require('fs');
//tor proxy
var proxy_ip_port = '127.0.0.1:9050';
//https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
var curl = new Curl(),
url = 'http://',
cookieJarFile = path.join(__dirname, 'cookiejar.txt');
if (!fs.existsSync(cookieJarFile)) {
fs.writeFileSync(cookieJarFile);
}
curl.setOpt(Curl.option.URL, 'https://hsto.org/r/w120/webt/59/cc/76/59cc7600c78a2239379574.jpeg');
curl.setOpt(Curl.option.VERBOSE, true);
curl.setOpt(Curl.option.COOKIEFILE, cookieJarFile);
curl.setOpt(Curl.option.COOKIEJAR, cookieJarFile);
curl.setOpt(Curl.option.FOLLOWLOCATION, 1);
curl.setOpt(Curl.option.HEADER, 0);
curl.setOpt(Curl.option.SSL_VERIFYPEER, 0);
curl.setOpt(Curl.option.SSL_VERIFYHOST, 0);
curl.setOpt(Curl.option.PROXYTYPE, Curl.proxy.SOCKS5_HOSTNAME);
curl.setOpt(Curl.option.PROXY, proxy_ip_port);
curl.perform();
curl.on('end', function(statusCode, body, headers) {
console.info('Status Code: ', statusCode);
console.info('Headers: ', headers);
console.info('Headers length: ', headers.length);
console.info('Body length: ', body.length);
//console.info('Body: ', body);
//console.info('METHOD: ', req.method);
console.info('HEADER_SIZE: ', curl.getInfo('HEADER_SIZE'));
for (var infoName in Curl.info) {
if (Curl.info.hasOwnProperty(infoName) && infoName !== 'debug') {
console.info(infoName, ': ', this.getInfo(infoName));
}
}
var fs1 = require('fs');
fs1.writeFile(path.join(__dirname, 'llllllllll.jpg'), body, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
this.close();
console.info('Cookie file contents:');
console.info(fs.readFileSync(cookieJarFile).toString('utf8'));
});
curl.on('error', curl.close.bind(curl));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question