How to use http-delete from the shell - http

Is it possible to send a HTTP DELETE request from the shell and if so, how?

curl -X delete URL
see (google cache, server seems slow) reference.

There are probably a lot of tools to do this, but the easiest, if you don't want to make sure those tools are available, might be to manually create your DELETE-request and send it to the server via telnet. I think the syntax is pretty much like this, although I've never used the delete command manually myself, only get and post.
DELETE /my/path/to/file HTTP/1.1
Host: www.example.com
Connection: close
There should be an extra newline (blank line) after the request to terminate it, but markdown won't allow me to do that. Store that in a file (or paste it in the console, if you don't want to use a script), then simply do
telnet www.example.com 80 < myRequest.txt
Of course, you can use a here-document as well.

Related

HTTP 400 of "AAAy H.mp3" but not "AAAy L.mp3"

Ok, this is weird, and I can fix it by getting rid of spaces, but what is going on?
I have two files on my website, AAAy H.mp3 and AAAy L.mp3. I can browse to them just fine.
When I do:
curl "http://mikehelland.com/omg/AAAy L.mp3"
I get the mp3 file.
When I do:
curl "http://mikehelland.com/omg/AAAy H.mp3"
I get 400, bad request. Also doing:
curl "http://mikehelland.com/omg/AAAY H.mp3"
yields a 400.
Change the H to an L or A or M or anything else seems to work fine. What's going on?
This is because of how server interprets space in file name, try to replace it with %20 (which represents space symbol in url) like this:
curl "http://mikehelland.com/omg/AAAy%20H.mp3"
If you try to acess your file with browser and will open developer console, you will found that browser inserts this %20 in GET request. So it is the reason why you can access file with browser, but not from terminal.
Also, try to add --verbose option to curl command. I noticed that when you access some inexistent file without space in name, the is the field in response 'Server: Apache/2', but when you add space it is 'Server: nginx'.
So maybe there is special case when server stops handling requset because it can't distinguish what to do with first line in request
GET /omg/AAAy H.mp3 HTTP/1.1
because it expects HTTP/1.1 after /omg/AAAy, but not weird H.mp3. And maybe server looks at first symbol in "H.mp3" when parse for HTTP, and it made things broken. So I think the reason why "/omg/AAAy H.mp3" doesn't work, but "/omg/AAAy L.mp3" works is due to parsing mechanism of the server. Of course, without %20 all variants are forbidden by standard.

CURL command not working with simple HTTP GET but browser does

I tried to fetch the data from https://m.jetstar.com/Ink.API/api/flightAvailability?LocaleKey=en_AU&ChildPaxCount=0&DepartureDate=2016-03-21T00%3A00%3A00&ModeSaleCode=&Destination=NGO&CurrencyCode=TWD&AdultPaxCount=1&ReturnDate=&InfantPaxCount=0&Origin=TPE
it couldn't be done by curl -vv https://m.jetstar.com/Ink.API/api/flightAvailability?LocaleKey=en_AU&ChildPaxCount=0&DepartureDate=2016-03-21T00%3A00%3A00&ModeSaleCode=&Destination=NGO&CurrencyCode=TWD&AdultPaxCount=1&ReturnDate=&InfantPaxCount=0&Origin=TPE it will return nothing,
However, browser can fetch whole data.
What's wrong with that?
It seems to me that "m.jetstar.com" is filtering requests that don't include the headers that a browser would send. Your curl statement needs to fully emulate a browser to get the data. One way to see what I'm saying is to open developer tools in Google Chrome, select the network tab, run the URL in the browser then goto to the row indicating the call and right click, then copy the request as a curl statement, then paste it to a notepad and you'll see all the additional headers you need. Additionally, that curl statement should work.
check if you have set any HTTP_REQUEST variable for proxy settings. Verify by calling curl command in verbose mode. curl -v
I had setup a variable earlier and when I check the curl output in verbose mode it told me that it was going to proxy address. Once I deleted the HTTP_REQUEST variable from advanced system settings, it started working. Hope it helps.

Vim edit file over http

I am trying to do this:
vim http://mysite.com/x.html
I have chmod 777 on the file to make sure full access is granted, I can open the file without a problem,
but when I tried to save the edit, there prompted an error:
"http://mysite.com/x.html" E212: Can't open file for writing
You (obviously) can't upload that file to the server via http.
Use ssh/scp or ftp.
See :help netrw.
http is the wrong protocol here. This makes for a good read: http://www.w3.org/blog/2008/10/understanding-http-put/ - the HTTP 'verbs' (PUT, POST, GET etc.) do not dictate how the server is going to handle the request you send. In fact HTTP "defines the intended semantics of the communication... (but) does not define how either side fulfills those expectations".
You could quite easily run
vim http://stackoverflow.com/questions/19476683/vim-edit-file-over-http
but you won't be able to edit this page.
See http://vim.wikia.com/wiki/Editing_remote_files_via_scp_in_vim for working on files via ssh / ftp.

How can I configure apache to send an email on every HTTP error 500

I have some server applications running on apache2; Ruby on Rails, PHP and others.
In all cases I would like apache to send me an email whenever apache responds a HTTP error 500 Internal server error.
How can I do that?
One way you can do this is use a php script that sends email, as well as output some sort of 500 message. Then use the ErrorDocument directive:
ErrorDocument 500 /path/to/script/that/sends/email.php
It is not possible to configure apache to send emails.
There are some things you can do to achieve the same result:
You can use the ErrorDocument directive to let it point to some CGI
script, that be a perl, PHP, or any other server-side executed
script. The script can then send an email and respond a Error 500
document.
You can use some external tool to watch your apache log
files and configure theese tools to send you emails. There are several tools and ways to do this. For Linux many
tools and methods are suggested on
https://serverfault.com/questions/45246/linux-monitor-logs-and-email-alerts
Write an apache module. I think that mod_tee is a good starting point.
Create a script called log_monitor.sh:
#!/usr/bin/perl -w
use strict;
my $cachefile="/var/cache/lastpos-apache2-scan4maxclntOrSigKill";
my $logfile="/var/log/httpd/error_log";
my $searchstr=" 500 ";
my $lastpos=0;
if (-f $cachefile) {
open FH,"<".$cachefile;
$lastpos=<FH>;
close FH;
};
my $newpos=(stat $logfile)[7];
open FH,"<".$logfile;
seek FH,$lastpos,0;
while (<FH>) {
print if m/$searchstr/i;
};
close FH;
open FH,">".$cachefile;
print FH $newpos;
close FH;
modify $searchstr as needed. note the spaces around "500", since you don't want to match errors which contain a 404 on a file that has "500" in its path or filename (among other places).
configure the script to run every X minutes via cron. the greater the value of X, the less emails you will get (only 1 email every X minutes for all the errors that match the strings you supply). the results of the cron job will get emailed to you automatically (if cron is setup properly)

Tamper with first line of URL request, in Firefox

I want to change first line of the HTTP header of my request, modifying the method and/or URL.
The (excellent) Tamperdata firefox plugin allows a developer to modify the headers of a request, but not the URL itself. This latter part is what I want to be able to do.
So something like...
GET http://foo.com/?foo=foo HTTP/1.1
... could become ...
GET http://bar.com/?bar=bar HTTP/1.1
For context, I need to tamper with (make correct) an erroneous request from Flash, to see if an error can be corrected by fixing the url.
Any ideas? Sounds like something that may need to be done on a proxy level. In which case, suggestions?
Check out Charles Proxy (multiplatform) and/or Fiddler2 (Windows only) for more client-side solutions - both of these run as a proxy and can modify requests before they get sent out to the server.
If you have access to the webserver and it's running Apache, you can set up some rewrite rules that will modify the URL before it gets processed by the main HTTP engine.
For those coming to this page from a search engine, I would also recommend the Burp Proxy suite: http://www.portswigger.net/burp/proxy.html
Although more specifically targeted towards security testing, it's still an invaluable tool.
If you're trying to intercept the HTTP packets and modify them on the way out, then Tamperdata may be route you want to take.
However, if you want minute control over these things, you'd be much better off simulating the entire browser session using a utility such as curl
Curl: http://curl.haxx.se/

Resources