0

On client side , following android code would make the call to the local server :

        String link = "http://localhost:8080/test/cgi-bin/test.py";
        URL url = null;
        try {
            url = new URL(link);

        HttpURLConnection client =  (HttpURLConnection) url.openConnection();

            JSONObject jo = new JSONObject();
            jo.put("desc","xyz");

            String data2 =  jo.toString();
            client.setRequestMethod("Post");
        //    client.setRequestProperty("key","value");
            client.setDoOutput(true);

            OutputStreamWriter outputPost = new OutputStreamWriter(client.getOutputStream());
            outputPost.write(data2);
            outputPost.flush();
            outputPost.close();

Earlier I was using servlets to interact with DB as the code below : Using HttpServlet class , i could get the request and its parameters :

public class ServletXYZ extends HttpServlet {

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        String method = request.getParameter("method");

Is there any way in python which allows me to do the same (getting parameter values from request) ?

Thanks.

devcodes
  • 1,038
  • 19
  • 38

1 Answers1

3

I've used CherryPy as a general purpose HTTP server framework. Ultimately to do the same as the servlet, there are many links - this one seems to be pretty much what you want.

Community
  • 1
  • 1
stdunbar
  • 16,263
  • 11
  • 31
  • 53
  • i started with cherrypy , would you know where to put my .py file which contains the processing of request and sending of response . And accordingly what url do i need to pass as link in client side – devcodes Aug 27 '16 at 21:08
  • by where i mean , certain directory of apache server which i am using locally – devcodes Aug 27 '16 at 21:15