Javascript Kód
const https = require('https');
const { SocksProxyAgent } = require('socks-proxy-agent');
const agent = new SocksProxyAgent('socks5h://127.0.0.1:9050');
https.get('https://nqieh33bhvzhm35l4qe4ifzbrbpxk4szwlu42wonqycvmqurlzptigyd.onion/api/v1/fees/recommended', {
agent
}, res => {
res.pipe(process.stdout);
});
vrací
Emitted 'error' event on ClientRequest instance at:
at onerror (*****/torapi/node_modules/agent-base/dist/src/index.js:117:21)
at callbackError (*****/torapi/node_modules/agent-base/dist/src/index.js:136:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
options: {
proxy: { host: '127.0.0.1', port: 9050, type: 5 },
destination: {
host: 'nqieh33bhvzhm35l4qe4ifzbrbpxk4szwlu42wonqycvmqurlzptigyd.onion',
port: 443
},
command: 'connect',
timeout: undefined
}
}
Process finished with exit code 1
pokud se url změní z https na http odpověď vypadá takto
node:_http_client:158
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
^
TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
at new NodeError (node:internal/errors:371:5)
at new ClientRequest (node:_http_client:158:11)
at request (node:https:353:10)
at Object.get (node:https:387:15)
at Object.<anonymous> (*****/torapi/index.js:6:7)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) {
code: 'ERR_INVALID_PROTOCOL'
}
PHP kód
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:9050');
curl_setopt($curl, CURLOPT_URL, "http://nqieh33bhvzhm35l4qe4ifzbrbpxk4szwlu42wonqycvmqurlzptigyd.onion/api/v1/fees/recommended");
echo(curl_exec($curl));
vrací očekávanou odpověď API
{"fastestFee":3,"halfHourFee":3,"hourFee":3,"minimumFee":1}