LWP::MediaTypes

S

spp

hello ,

I am using LWP::MeidaTypes package to get the mediatype. If it doesnt
recognize the type it returns media type as: application/octet-stream.
I am using its add_type function to add some extentions like bmp, php
etc. but its add_type doesnt seem to be working.
or may be I am doing something wrong.

My code :

use LWP::MediaTypes qw(add_type guess_media_type);

add_type("text/special")=>qw(shtml php htm);

add_type("image/special")=>qw(bmp png jpeg);


my $type = guess_media_type("http://www.cnn.com/abc.php" );
print "media type is". $type;

#
if i run this it prints media type is application/octet-stream

can anyone please tell me what am I doing wrong?
Thanks in advance,
SP
 
D

David Squire

spp said:
hello ,

I am using LWP::MeidaTypes package to get the mediatype. If it doesnt
recognize the type it returns media type as: application/octet-stream.
I am using its add_type function to add some extentions like bmp, php
etc. but its add_type doesnt seem to be working.
or may be I am doing something wrong.

My code :

use LWP::MediaTypes qw(add_type guess_media_type);

add_type("text/special")=>qw(shtml php htm);

add_type("image/special")=>qw(bmp png jpeg);


my $type = guess_media_type("http://www.cnn.com/abc.php" );
print "media type is". $type;

#
if i run this it prints media type is application/octet-stream

Could you please give us a *real example*, as a *small but complete*
script? For a start, "http://www.cnn.com/abc.php" does not exist, and
the 404 page that the CNN site generates begins:

HTTP/1.1 404 Not Found
Date: Fri, 23 Jun 2006 18:51:32 GMT
Server: Apache
Vary: Accept-Encoding,User-Agent
Cache-Control: private
Content-Type: text/html
Content-Length: 23584
Connection: close

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
....

DS
 
B

Ben Morrow

Quoth "spp said:
hello ,

I am using LWP::MeidaTypes package to get the mediatype. If it doesnt
recognize the type it returns media type as: application/octet-stream.
I am using its add_type function to add some extentions like bmp, php
etc. but its add_type doesnt seem to be working.
or may be I am doing something wrong.

My code :

use LWP::MediaTypes qw(add_type guess_media_type);

add_type("text/special")=>qw(shtml php htm);

add_type("image/special")=>qw(bmp png jpeg);


my $type = guess_media_type("http://www.cnn.com/abc.php" );
print "media type is". $type;

#
if i run this it prints media type is application/octet-stream

can anyone please tell me what am I doing wrong?

URIs should be given as a ref to a URI object. This is not entirely
clear from the documentation.

Ben
 
D

David Squire

spp said:

No. Real example of your small but complete script.

For what it's worth, the header for that one is:


HTTP/1.1 302 Found
Date: Fri, 23 Jun 2006 19:23:54 GMT
Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7e PHP/4.4.1 DAV/2
X-Powered-By: PHP/4.4.1
location: http://www.uccs.edu/~webdept/az/azstatic/A.html
Content-Length: 7694
Content-Type: text/html; charset=ISO-8859-1


It correctly reports its content-type as text/html. Why would you want
to change that?

DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top