Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Dec 01, 2023 3:19 pm


Tutorials applicable on more than one Unix/Linux OS and shell scripts: ssh / openssl / protocols.

Author Message
debuser
Post  Post subject: Using curl to get the HTTP response from an HTTP server  |  Posted: Sun Jun 06, 2010 9:05 am

Joined: Thu Aug 06, 2009 2:48 am
Posts: 105

Offline
 

Using curl to get the HTTP response from an HTTP server

Using curl to get the HTTP response from an HTTP server.

Syntax: curl --head http://www.site.name

Quote:
curl(1) Curl Manual curl(1)

NAME
curl - transfer a URL

SYNOPSIS
curl [options] [URL...]

DESCRIPTION
curl is a tool to transfer data from or to a server, using one of the
supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT,
TELNET, LDAP or FILE). The command is designed to work without user
interaction.

curl offers a busload of useful tricks like proxy support, user authen-
tication, ftp upload, HTTP post, SSL connections, cookies, file trans-
fer resume and more. As you will see below, the amount of features will
make your head spin!

curl is powered by libcurl for all transfer-related features. See
libcurl(3) for details.

-I/--head
(HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature
the command HEAD which this uses to get nothing but the header
of a document. When used on a FTP or FILE file, curl displays
the file size and last modification time only.

If this option is used twice, the second will again disable
header only.


Code:
$ curl --head http://www.google.cz
HTTP/1.1 200 OK
Date: Sun, 06 Jun 2010 13:02:15 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-2
Set-Cookie: PREF=ID=bd077f51a60704c8:TM=1275829335:LM=1275829335:S=P9IvQj_4SmpaSGqp; expires=Tue, 05-Jun-2012 13:02:15 GMT; path=/; domain=.google.cz
Server: gws
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked





Top
wnbv85
Post  Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Posted: Thu Dec 01, 2011 8:07 am

Joined: Tue Nov 29, 2011 9:41 am
Posts: 3

Offline
hi
function http_response($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

echo $httpCode ;
}

I am developing a software which will be communicating with a server using HTTP (but it is not a web browser). Since the server part is not ready yet, I would like to debug my client software by sending HTTP messages to it. I know that I can send HTTP requests using Curl. But I am not sure if that is sufficient here.

I'm imagining an environment where I send a request from my application, check that it is correct using Wireshark and then reply to the request using some software. Using Curl, I think I would have open a listening port..?


Top
admin
Post  Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Posted: Tue Dec 06, 2011 8:45 am
Site Admin

Joined: Mon Aug 03, 2009 8:43 am
Posts: 104

Offline
You can use netcat utility to open an http port:
Code:
# nc -v -l 80 &
# lsof -Pni :80
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
nc      1466 root    3u  IPv4   6349       TCP *:80 (LISTEN)



First command runs nc with "verbose" and "listen to port 80" instructions in background mode.

From the same terminal you can send some text to port 80 on localhost (where nc is listening as server) and it will output it to the standard output:
Code:
# echo 'test output' | nc localhost 80
Connection from 127.0.0.1 port 80 [tcp/http] accepted
test output

_________________
VPSie - SSD VPS servers in AMS-IX, LINX, DE-CIX
https://vpsie.com


Top
admin
Post  Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Posted: Tue Dec 06, 2011 9:05 am
Site Admin

Joined: Mon Aug 03, 2009 8:43 am
Posts: 104

Offline
Server:
Code:
# echo 'HTTP/1.1 OK' | nc -l 80
asdf


Client:
Code:
# echo asdf | nc localhost 80
HTTP/1.1 OK

_________________
VPSie - SSD VPS servers in AMS-IX, LINX, DE-CIX
https://vpsie.com


Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Using curl to get the HTTP response from an HTTP server"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Using echo, netcat(nc) and tr to create an HTTP connection

debuser

0

3365

Thu Mar 04, 2010 5:01 am

debuser View the latest post

There are no new unread posts for this topic. How to check SSL ciphers used in a web server's configuration ciphersuites

mandrei99

1

19139

Fri May 04, 2012 6:28 am

mandrei99 View the latest post

There are no new unread posts for this topic. Openssl s_client command line: connect and diagnose an https server

LaR3

0

5687

Wed Aug 26, 2009 3:18 am

LaR3 View the latest post

There are no new unread posts for this topic. Invalid command 'AddHandler', perhaps misspelled or defined by a module not included in the server..

debuser

0

5509

Thu Jul 22, 2010 2:30 pm

debuser View the latest post

There are no new unread posts for this topic. Invalid command 'Order', perhaps misspelled or defined by a module not included in the server config

debuser

0

4769

Tue Jan 12, 2010 7:25 am

debuser View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO