Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want is basically a very simple web server, but if all you want is printing out what comes in a HTTP POST request you can get away with using the built-in 'nc' command. You can use Terminal to print out the contents of incoming requests on local port 10000 by running 'nc' in a loop like this:</p> <pre><code>while true; do nc -l 10000 &lt; /dev/null ; printf '\n\n\n'; done </code></pre> <p>You can then go to <code>http://localhost:10000</code> in your browser and see the HTTP request appear in your Terminal window. The web browser will give an error message since 'nc' isn't smart enough to reply.</p> <p>To test an HTTP POST request you can use 'curl':</p> <pre><code>curl --data "this-is-POST-data" http://localhost:10000 </code></pre> <p>Again, curl will give an error message because 'nc' simply closes the connection without giving a proper HTTP reply. You can have 'nc' reply with a static HTTP response to all requests like this:</p> <pre><code>while true; do printf 'HTTP/1.0 200 OK\r\nContent-type: text-plain\r\n\r\nHello, world!' | nc -l 10000 ; printf '\n\n\n'; done </code></pre> <p>If you need to use port 80 you'll need to run 'nc' as root (e.g. using 'sudo').</p> <p>If you need to have any kind of real HTTP traffic going on, however, you will need to get a proper web server. OS X comes with the Apache web server which can be started with the command "apachectl start" ("apachectl stop" to stop it). CGI is enabled so you can put executables into /Library/WebServer/CGI-Executables and access them using <code>http://localhost/cgi-bin/filename</code>. For example, if you create the following CGI script:</p> <pre><code>#!/bin/sh printf 'Content-type: text/plain\r\n\r\n' cat &gt; /tmp/post-data echo OK </code></pre> <p>call it, say, "test.sh" and place it in the CGI-Executables folder, and run:</p> <pre><code>chmod +x /Library/WebServer/CGI-Executables/test.sh </code></pre> <p>Then, whenever you send a POST request to <code>http://localhost/cgi-bin/test.sh</code> it will save the contents of the POST data to the file /tmp/post-data on your computer.</p> <p>Note: in all examples, "localhost" can be replaced with "macbook-pro.local" for accesses over the network if that is your computer hostname.</p> <p>Also note that your OS X firewall permissions may block 'nc' and other software from listening to TCP ports. Usually you should get a permission dialog, but if you simply get "permission denied", tweak your firewall settings in System Preferences -> Firewall -> Firewall Options.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload