Reputation: 2934
I am trying to POST a form to a 3rd-party web server.
The form is like this:
<form method=post action="http://www.domain.com/path/page.do?id=18&localeCode=en-us">
<input type="submit" name="FILTER:name=init" value="Submit" />
</form>
If I load this HTML into a browser and submit the form, the correct page is returned by the web server. If I submit it from Swift using Alamofire all is well.
But on App Engine, using urllib2 or urlfetch a different HTML page is returned.
from google.appengine.api import urlfetch
page = urlfetch.fetch(
url="http://www.domain.com/path/page.do?id=18&localeCode=en-us",
payload={"FILTER:name=init" : "Submit"},
method=urlfetch.POST,
headers={"Content-Type": "application/x-www-form-urlencoded"},
deadline=30)
For the payload I've tried encoding name=init as name%3Dinit but without any further success.
Upvotes: 1
Views: 463
Reputation: 6893
You need to urlencode your payload dict manually before passing to urlfetch.fetch
. See the example from the docs below.
import urllib
from google.appengine.api import urlfetch
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "[email protected]"
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
Upvotes: 5