|
Tutorials applicable on more than one Unix/Linux OS and shell scripts: ssh / openssl / protocols.
Author |
Message |
debuser
|
 |
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
|
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.nameQuote: 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
|
|
|
|
|
|
wnbv85
|
 |
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
|
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..?
|
|
|
|
|
admin
|
 |
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
|
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
|
|
|
|
|
admin
|
 |
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
|
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
|
|
|
|
|
|
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
|
News Site map SitemapIndex RSS Feed Channel list
|
|