Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Dec 242010
 

Use insecure SSL connections and transfers with curl

Answer:

If you have a self-signed SSL certificate with your server, and you want to connect to it using the curl command, you need to use the " -k/--insecure" option since curl only use the CA certificate bundle installed by default.

Example:

# curl -k https://localhost

Dec 232010
 

Show HTTP response using curl command

Answer:

curl is a very powerful tool for transferring data from or to a server, which support many protocols such as HTTP, HTTPS, FTP etc.

Example: Issue a HTTP request to a remote server.

# curl -v http://www.example.com

* About to connect() to www.example.com port 80 (#0)
*   Trying 192.0.32.10... connected
* Connected to www.example.com (192.0.32.10) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15
> Host: www.example.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache
< Last-Modified: Fri, 30 Jul 2010 15:30:18 GMT
< ETag: "573c1-254-48c9c87349680"
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Connection: Keep-Alive
< Date: Wed, 22 Dec 2010 16:19:06 GMT
< Age: 817
< Content-Length: 596
...
Dec 222010
 

Get HTTP request with nc command

Answer:

nc command is a very useful tool for network diagnosis, e.g. when you want to know the exact requests sent by your HTTP client (e.g. browser) to your web server, you can easy test with nc.

1. In your server, start nc and listen on port 80

# sudo nc -l -p 80

2. In your browser, type the server IP address.

3. In your shell, HTTP requests will be printed.

GET / HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090712 Firefox/3.5.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Dec 212010
 

How can I find out my current package in Perl?

Answer:

To find the current package in your Perl script, you can try something like the following:

package Foo;

my $current_package = __PACKAGE__;
print "I am in package $current_package\n";

1;

When executed:

# perl foo.pl

I am in package Foo