Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete files using LWP

Status
Not open for further replies.

johnv20

Programmer
Sep 26, 2001
292
US
Hi,

I know this should be very simple but does anyone have any code which is used to delete a file over a url using LWP ?
 
Unfortunately no - FTP is not allowed on any of these web servers

Alternatively I have been trying to PUT a 0 byte file but cannot seem to get it to work any ideas ?

Code:
use LWP::UserAgent;
use HTTP::Request;



$request = HTTP::Request->new(PUT => '[URL unfurl="true"]http://myserver/mydir/file1.log');[/URL]
$ua = LWP::UserAgent->new;
$response = $ua->request($request);
 
According to the W3C, HTTP should support a DELETE method.
9.7 DELETE

The DELETE method requests that the origin server delete the resource
identified by the Request-URI. This method MAY be overridden by human
intervention (or other means) on the origin server. The client cannot
be guaranteed that the operation has been carried out, even if the
status code returned from the origin server indicates that the action
has been completed successfully. However, the server SHOULD NOT
indicate success unless, at the time the response is given, it
intends to delete the resource or move it to an inaccessible
location.

A successful response SHOULD be 200 (OK) if the response includes an
entity describing the status, 202 (Accepted) if the action has not
yet been enacted, or 204 (No Content) if the action has been enacted
but the response does not include an entity.

If the request passes through a cache and the Request-URI identifies
one or more currently cached entities, those entries SHOULD be
treated as stale. Responses to this method are not cacheable.
However, most sane webadmins probably don't allow this.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Yep - knew I wasn't sane when I allowed it.

But as far as I can understand it LWP does not allow a delete method anyway.

So.. does anyone have a quick piece of code which will allow me to use the PUT method for HTTP::Request.

I've been trying to implement following the instructions on CPAN but cannot get it to work for some reason.
 
Even using a PUT request, you'll still need something server-side to carry out whatever action you're expecting to happen on receipt of the request. The mere act of sending the request to the web server won't have any effect (similar to how you'd handle a POST request). Have a look here for more on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top