Categories
Protocols

HTTP headers for binary file downloads

In case you need to send files from a webserver, use these HTTP headers:

Content-Type:application/octet-stream
Content-Disposition:attachment;filename=filename
Content-Length:100

Of course, you need to set your own content type, filename and file length. 🙂

Categories
Java PHP Perl

URL Parameter Transforming

Need to transform URL parameters and decode values such as “Hello%20World!”? Here is how:

Perl:

$s =~ s/%([\da-f][\da-f])/chr( hex($1) )/egi;

Java:

s = java.net.URLEncoder.encode(s, "UTF-8");

PHP:

$s = urldecode($s);