Log in

View Full Version : http from the command line



kosi
06-02-2007, 02:23 AM
Does anybody know the syntax for performing an http get or http post request from the command line? Thanks.

Twey
06-02-2007, 04:38 PM
Which command line? Using what program? With what data?

The general format for a minimal GET request is:
GET /path/to/resource HTTP/1.1
Host: www.example.com
Connection: close
<blank line>

mburt
06-02-2007, 05:53 PM
I think the OP wants to access information similarly to the way AJAX does from a server... just a guess, though.

ItsMeOnly
06-03-2007, 10:53 AM
telnet yourserver.com 80
GET /
Just a thought

Twey
06-03-2007, 12:44 PM
That request lacks the HTTP version and the Host header, which is vital for HTTP/1.1. A correct GET request should look as mine does above (although the Connection header isn't vital).

kosi
06-07-2007, 06:26 AM
Which command line? Using what program? With what data?

My apologies if I was too vague. I'm using php. I know that php has a function class that does this, but it's not bundled on my server, so I thought I'd use shell scripting on the command line with the exec() function. I need to send name-value pairs to another server using the POST method and with no form. I also need to get name-value pairs back from that server, but I'm assuming this is as simple as "extract($_POST);".

Twey
06-07-2007, 10:27 AM
You'll need to write a basic HTTP client using fsockopen (http://www.php.net/fsockopen)().

mburt
06-07-2007, 12:53 PM
Wouldn't exec() work fine?

Twey
06-07-2007, 05:15 PM
Well yes, but fsockopen() would be simpler, and more likely to work.

kosi
06-07-2007, 08:11 PM
Well yes, but fsockopen() would be simpler, and more likely to work.

I don't really know what this means . . .

edit: I'm sorry, I'm being vague again. What i meant to say is that I dont understand the documentation at php.net.

Twey
06-07-2007, 08:16 PM
It's very simple. Use fsockopen() to open a connection to a server, then you can read from and write to it like a normal file.

kosi
06-07-2007, 08:23 PM
It's very simple. Use fsockopen() to open a connection to a server, then you can read from and write to it like a normal file.

Okay, I think i get it now. Thanks. I'll mess around with this tonight when i get home.