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

FAQ
It is currently Mon Nov 18, 2019 10:52 am


Username:
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
Font size:
 
Font colour
Options:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Disable BBCode
Disable smilies
Do not automatically parse URLs
Confirmation code
Confirmation code:
In an effort to prevent automatic submissions, we require that you enter both of the words displayed into the text field underneath.
     

Topic review - Using curl to get the HTTP response from an HTTP server
Author Message
Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Post Posted: Tue Dec 06, 2011 9:05 am
Server:
Code:
# echo 'HTTP/1.1 OK' | nc -l 80
asdf


Client:
Code:
# echo asdf | nc localhost 80
HTTP/1.1 OK
Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Post Posted: Tue Dec 06, 2011 8:45 am
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
Post subject: Re: Using curl to get the HTTP response from an HTTP server  |  Post Posted: Thu Dec 01, 2011 8:07 am
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..?
Post subject: Using curl to get the HTTP response from an HTTP server  |  Post Posted: Sun Jun 06, 2010 9:05 am
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
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