postget-dev

dev.postget.http
Class PostgetDevServlet

java.lang.Object
  javax.servlet.GenericServlet
      javax.servlet.http.HttpServlet
          dev.postget.http.PostgetDevServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class PostgetDevServlet
extends javax.servlet.http.HttpServlet

Relays a GET as a POST. A servlet for clients that can only send a GET. The caller writes the address and the body of a request into a link and fetches the link; the servlet sends that request as a POST, or with another method if one is asked for, and returns the other side's answer. Custom headers are passed on. Any public http or https address can be reached. No account and no key is needed, and there is no charge.

Example:

postget-dev: Relays a GET as a POST

Put the address and the body in a link and fetch it. This POSTs
{"name":"test"} to https://example.com/api and gives you whatever
example.com answered, status code and headers included:

    https://www.postget.dev/api/post?url=https://example.com/api&body=%7B%22name%22%3A%22test%22%7D

With curl, which does the encoding for you:

    curl -G https://www.postget.dev/api/post --data-urlencode 'url=https://example.com/api' --data-urlencode 'body={"name":"test"}'

Something other than a POST, or with headers of your own:

    https://www.postget.dev/api/post?url=https://example.com/api/7&method=DELETE
    https://www.postget.dev/api/post?url=https://example.com/api/7&method=PUT&body=name%3Dnew&headers=%7B%22Authorization%22%3A%22Bearer%20abc%22%7D

headers is a JSON object, here {"Authorization":"Bearer abc"}. A body
that is JSON goes out as application/json, a=1&b=2 as a form, anything
else as text; content_type=... says otherwise. Add response=json to
get the answer wrapped in an object with "status", "headers" and
"body". http and https only. Redirects are followed. No key, no
account.

See Also:
Serialized Form

Constructor Summary
PostgetDevServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Reads the request written into the link, sends it on and returns the answer.
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Provided for completeness; callers are expected to arrive by GET.
 java.lang.String getServletInfo()
          Returns the name of this servlet.
protected  void sendOn(java.lang.String dest, byte[] data)
          Deprecated. 
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Receives every request and hands it to the method that answers it.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostgetDevServlet

public PostgetDevServlet()
Method Detail

doGet

protected void doGet(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     java.io.IOException
Reads the request written into the link, sends it to the address named there with the method asked for, and returns the other side's answer to the caller. The method is POST unless another is asked for. Headers given by the caller are sent along.

To invoke this method from a browser:




From a shell the same request is:
curl -G https://www.postget.dev/api/post --data-urlencode 'url=https://example.com/api' --data-urlencode 'body={"name":"test"}'
Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
req - the request as it arrived, a GET with the real request written into it
resp - the response, which receives the other side's answer
Throws:
javax.servlet.ServletException - if the request cannot be relayed
java.io.IOException - if the other side cannot be reached or stops answering

doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      java.io.IOException
Provided for completeness. A caller that can send a POST of its own has no need of this servlet; callers are expected to arrive by GET.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - the request as it arrived, a GET with the real request written into it
resp - the response, which receives the other side's answer
Throws:
javax.servlet.ServletException - if the request cannot be relayed
java.io.IOException - if the other side cannot be reached or stops answering

service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws javax.servlet.ServletException,
                       java.io.IOException
Receives every request and hands it to the method that answers it. Only public http and https addresses are relayed to.

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - the request as it arrived, a GET with the real request written into it
resp - the response, which receives the other side's answer
Throws:
javax.servlet.ServletException - if the request cannot be relayed
java.io.IOException - if the other side cannot be reached or stops answering

sendOn

protected void sendOn(java.lang.String dest,
                      byte[] data)
               throws java.io.IOException
Deprecated. 

Sends the given bytes to the given address as a POST.

Parameters:
dest - where to send
data - what to send
Throws:
java.io.IOException

getServletInfo

public java.lang.String getServletInfo()
Returns the name of this servlet.

Returns:
the string postget-dev

postget-dev

Generated from the source comments. The build that made this page is long gone; the servlet is not.
Generated on Tue Mar 09 14:22:07 CET 2004