Skip to content
Related Articles

Related Articles

Calling Web Service Using Curl With Telnet Connection

View Discussion
Improve Article
Save Article
  • Last Updated : 08 Jul, 2022
View Discussion
Improve Article
Save Article

Prerequisite: Telnet, Curl

Terminal Network as the name suggests is an application layer protocol used to connect with hosts (remote machines) over a TCP/IP network. It is based on a client-server architecture where the telnet client makes a connection with the telnet server and once the connection has been established the client (your computer) acts as a terminal allowing you to come with the host using your computer. All information that is being exchanged between telnet client and server is unencrypted, that’s why SSH is being used today.

You can connect to the host using the command prompt on Windows or using a specified CLI in your OS. If you want to test the local web service over a telnet connection.

telnet localhost/remotehost 80
Connecting with localhost/remote host using telnet

 

Here, the host is the IP address of the host and the port is the port number on which the service is running (80 for HTTP). But remember, Telnet only works on TCP Port. Alternatively, you can specify an IP address instead of a name. 

To look up for IP address, you can type nslookup google.com  in your command prompt.

CURL:

A curl is just a tool that can be integrated with telnet to transfer data between client and server using Telnet protocol. Remember it can even use other protocols such as HTTP, HTTPS, FTP, and FTPS for transferring data. Here I’ll only talk about how we can use Curl with Telnet.

Now let’s talk about how we can integrate curl with Telnet Connection.

When we use curl with telnet, we tell curl to fetch the telnet URL so that it can send whatever it reads on stdin to a remote server and output whatever the server sends.

To connect to your local HTTP server running on port 80, type the following command. Remember you might need to configure your firewall and check for the inbound rule of services as it might have been disabled, in that case, you won’t be able to connect.

curl -v telnet://localhost:80
Connecting localhost by using curl with telnet

 

Here ‘-v’ refer to verbose which provides a brief explanation of what goes well or what went wrong. For example, if you want to test whether www.google.com is responding on port 443(HTTPS).

curl -v telnet://www.google.com:443
Connect remote host by using curl with telnet

 

You’ll be connected successfully if the port is open for making a connection. To terminate the session, you can use Ctrl+ C. Try to connect to port 21 or 23. You’ll get ‘failed to connect‘ when the Google server has configured a firewall that restricts connection according to inbound and outbound rules. You can even configure your firewall and make new rules by going to the advanced setting of your Firewall. Therefore, it’s a great tool for testing changes done in the firewall.

Could not resolve host since the port is not open for connection

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!