0

NOTE: How to use basic authorization in PHP curl Does not work for me.

$password = 'root';         
$username = 'password';
$URL='http://127.0.0.1';   //Curl into own machine local ip is needed.
$port = 7777;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result=curl_exec($ch);

if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); }

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   

curl_close ($ch);

echo "<br>";
var_dump($result);
echo "<br>";
var_dump($status_code);

Below is my error

Error:

bool(false)

int(0)

Below are my netstats. Port is open and listening.

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:7777          0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN           

PHP7, PHP-CURL & CURL are installed on linux Fedora 27. Webserver type Apache 2.4

Trying to Curl into Electrum

seamus
  • 2,681
  • 7
  • 26
  • 49
  • 1
    I don't think you can SSH using CURL lib... – ariefbayu Apr 04 '18 at 09:01
  • 2
    sshd in general will not 'speak' https, so I am not sure what you are attempting to achieve here. – KillerX Apr 04 '18 at 09:01
  • Thank you did not know. Changed it back to original port trying to connect to 7777. If this is a ssh port how can I change it to a http port? – seamus Apr 04 '18 at 09:03
  • 2
    The web server listens on port `80` (the default HTTP port). You are trying to connect to port `22` where `sshd` listens but `sshd` doesn't understand HTTP (or HTTPS) and `curl` doesn't know the SSH protocol. Why do you attempt to connect to `localhost:22`? – axiac Apr 04 '18 at 09:03
  • Do you have an HTTP server listening on port `7777`? It is not listed in the dump of `netstat` you posted. – axiac Apr 04 '18 at 09:05
  • 1
    You need to run a webserver to listen on port `7777` and handle your curl request – Hendri Apr 04 '18 at 09:06
  • With regards to listen on port 7777. I have tried the command 'Listen 7777' but a 'command not found' was returned – seamus Apr 04 '18 at 09:10
  • 1
    Tried it where? If you don't *already* have a webserver listening on port 7777, where has that number come from? – iainn Apr 04 '18 at 09:11
  • Port 7777 will appear on netstat after i Daemon Start the program I am trying to curl to. However, the port 7777 does not stay on Listen. – seamus Apr 04 '18 at 09:21
  • Maybe you could explain what you are trying to do. Do you have another program that listens on port 7777? Which protocol does it use? Is it third party or can you change it? – Karsten Koop Apr 04 '18 at 09:28
  • Electrum wallet. It used 'HTTP basic auth' – seamus Apr 04 '18 at 09:33

0 Answers0