Reputation: 10471
I'm trying to send a GET request to a App Engine server from a page built with Django. I set the parameters in Django part, but in App Engine the parameter value is empty.
I've logged its value in Django side, and the parameters values are ok.
Here is my Django code:
try:
username = request.session['username']
params = urllib.urlencode('user', username)
headers = {"Content-type":"application/x-www-form-urlencoded", "Accept":"text/plain"}
conn = httplib.HTTPConnection(connections_strings.auth)
conn.request("GET", connections_strings.auth, params, headers)
response = conn.getresponse()
jsonString = response.read()
return render_to_response('home/index.html', locals(), context_instance=RequestContext(request))
And here is the App Engine code:
def get(self):
username = self.request.get('user') # Get the username parameter
query_user = UserEntity.all()
query_user.filter('username = ', username)
user_data = []
for user in query_user:
record = { //Create the JSON.. }
user_data.append(record)
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(simplejson.dumps(user_data))
The get(self)
method in App Engine is being called, I've put a log message there and it has been printed.
So, what is happening is that in the App Engine side, self.request.get('user')
returns nothing. And it's weird, I've made GET
request from mobile side, and it works perfectly with this same method.
Any idea??
Thanks!
Upvotes: 0
Views: 606
Reputation: 9041
In a HTTP GET method, the query parameters are passed in the URL:
http://example.com?user=foo
The request()
method is defined like this:
HTTPConnection.request(method, url[, body[, headers]])
So by doing this:
conn.request("GET", connections_strings.auth, params, headers)
you've sent the params in the request body instead.
Try this instead:
selector = '{}?{}'.format(connections_strings.auth, params)
conn.request("GET", selector, headers=headers)
Upvotes: 3