Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

C (F)CGI for tunneling POST over GET for cross-site JSONP POST requests

branch: master

minor TODO edit

latest commit 04f98e4300
Alan Dipert authored December 25, 2008
Octocat-spinner-32 patches makefile finally fixed... maybe December 18, 2008
Octocat-spinner-32 LIGHTTPD.EXAMPLE.CONF example conf rename December 18, 2008
Octocat-spinner-32 Makefile further Makefile optimization December 18, 2008
Octocat-spinner-32 QUICKSTART example conf rename December 18, 2008
Octocat-spinner-32 README shoutouts in readme December 18, 2008
Octocat-spinner-32 TODO minor TODO edit December 25, 2008
Octocat-spinner-32 error.c more comments December 25, 2008
Octocat-spinner-32 fetch.c more comments December 25, 2008
Octocat-spinner-32 jsonptunnel.h fcgi/cgi creation in same makefile, consolidated fastcgi cgic patch December 18, 2008
Octocat-spinner-32 main.c fcgi ifdefs December 18, 2008
Octocat-spinner-32 request.c more comments December 25, 2008

  This is a C fastcgi/cgi that "mirrors" web services available via HTTP POST.

  The reason you might want to do this is to access off-site
  JSON data sources from scripts via JSONP.

  Because the trick behind JSONP is dynamically adding "<script>" nodes
  to the DOM with the DOM API, it's intrinsically limited to external
  scripts available with an HTTP "GET."

  This CGI lets you send HTTP POST data to off-site URLs, and
  retrieve the result, with an HTTP GET - it 'tunnels' GET 
  to POST.


  jsonptunnel.cgi itself looks for two GET variables, one of which 
  is required:


      1. extURL - the URL to POST to.


      1. extCallback - wraps the off-site output with a function
                       named this parameter, taking the returned
                       data as its only parameter.  Many JSONP
                       web services provide their own 'callback'
                       parameter; if they don't, you can use this.


      jsonptunnel sends any variables you specify in the query
      string other than the ext* variables to the target URL.


      This is a page using Mootools with the JsonP extension from clientcide.
      It's an example of how to tunnel a POST request across domains to a
      simple web service that adds two numbers, and display the result.



  1. make get-cgic
  2. make cgi
  3. copy jsonptunnel.cgi to your cgi-bin (or equivalent).


  1. make get-cgic
  2. make fcgi
  3. Configure your web server to run jsonptunnel.fcgi. See "LIGHTTPD.EXAMPLE.CONF"
     for an example configuration.

  You may have to modify the Makefile variable FCGI_INCLUDE to point 
  to the location of the FastCGI header files on your system.


  To switch between fcgi and cgi builds, 'make clean'
  before running 'make cgi' or 'make fcgi.'


  1. libcurl -
  2. libcgic - 
               download and patch automatically with 'make get-cgic' command.
  3. FastCGI -

  jsonptunnel requires libcurl, libcgic, and fastcgi.  libcurl is pretty common,
  libcgic is not.  The 'make get-cgic' command downloads cgic into the
  current directory and a subsequent make command will build the library
  and link against it.


  I'd like to thank the CURL team,, and the FastCGI guys
  for making such awesome software.
Something went wrong with that request. Please try again.