Python sending and receiving HTTP POST
Question: I am in the process of learning Python and I am trying to do something really
simple: send an HTTP POST from one application and receive it in the other,
not only I can't get it to work, I can't get it to work with what would seem
reasonable, using def post(self). This is the code I have, which doesn't give
errors, but doesn't do the task either: Sender Application:

    
    
    import cgi
    import webapp2
    import urllib
    import urllib2
    import json
    
    from google.appengine.api import urlfetch
    from google.appengine.ext import webapp
    
    senddata = {}
    senddata["message"] = 'Testing the Sender'
    
    
    class MainPagePost(webapp2.RequestHandler):
    
        def get(self):
            txt_url_values = urllib.urlencode(senddata)
            txturl = 'http://localhost:10080'
            result = urllib.urlopen(txturl, txt_url_values)
            self.redirect('http://localhost:10080') 
    
    application = webapp2.WSGIApplication([
        ('/', MainPagePost), 
    ], debug=True)
    

Recieving Application:

    
    
    import cgi
    import webapp2
    import urllib
    import urllib2
    import json
    
    from google.appengine.api import urlfetch
    from google.appengine.ext import webapp
    
    class MainPageGet(webapp2.RequestHandler):
    
        def get(self):
            self.response.write('you sent:')
            con = self.request.get("message")
            self.response.write(con)
    
    application = webapp2.WSGIApplication([
        ('/', MainPageGet), 
    ], debug=True)
    

All I get on the localhost is "you sent:" :( Worst of all I don't understand
why both defs need to be "get(self)" so that I don't get 405 error... Thanks
all :)

This is the "new" code, for the sender no change:

    
    
    import cgi
    import webapp2
    import urllib
    import urllib2
    import json
    
    from google.appengine.api import urlfetch
    from google.appengine.ext import webapp
    
    senddata = {}
    senddata["message"] = 'Testing Tester'
    
    
    class MainPagePost(webapp2.RequestHandler):
    
        def get(self):
            txt_url_values = urllib.urlencode(senddata)
            txturl = 'http://localhost:10080'
            result = urllib.urlopen(txturl, txt_url_values)
            self.redirect('http://localhost:10080') 
    
    application = webapp2.WSGIApplication([
        ('/', MainPagePost), 
    ], debug=True)
    

The receiver I changed to post, as Sam suggested, but I am getting 405:

    
    
    # -*- coding: utf-8 -*-
    import cgi
    import webapp2
    import urllib
    import urllib2
    import json
    
    from google.appengine.api import urlfetch
    from google.appengine.ext import webapp
    
    class MainPageGet(webapp2.RequestHandler):
    
        def post(self):
            # self.response.write('you sent:')
            con = self.request.get("message")
            self.response.write('you sent: ' + con)
    
    application = webapp2.WSGIApplication([
        ('/', MainPageGet), 
    ], debug=True)
    

Thanks :)


Answer: Check this [example](http://webapp-improved.appspot.com/guide/response.html):

    
    
    self.response.write("<html><body><p>Hi there!</p></body></html>")
    

> The response buffers all output in memory, then sends the final output when
> the handler exits. webapp2 does not support streaming data to the client.

so basically, response.write must be the last thing you call:

    
    
    def get(self):            
            con = self.request.get("message")
            self.response.write("you sent: " + con )
    

Also, I suggest you check this
[link](https://developers.google.com/appengine/docs/python/gettingstartedpython27/handlingforms)
to read more about POST and GET requests with forms on Appengine. I don't
understand what you're trying to do with those two views, but they clash with
each other

