简体   繁体   中英

Sending a URL in a GET request to a Python server on Google App Engine

I have written a very simple server in Python on Google Apps engine. I want to be able to send it a command via a GET request, such as "http://myserver.appspot.com/?do=http://webpage.com/?secondary=parameter"

This does not work, as the secondary parameter gets interpreted separately and sent to my app as well. Any help?

The url http://myserver.appspot.com/?do=http://webpage.com/?secondary=parameter is uncorrectly formed. Perhaps you can urlencode the string data and then send it

from urllib import urlencode
data = {"do": "http://webpage.com/?secondary=parameter"}
encoded_data = urlencode(data)
url = "http://myserver.appspot.com/?" + encoded_data

Gives output

>>> print url
http://myserver.appspot.com/?do=http%3A%2F%2Fwebpage.com%2F%3Fsecondary%3Dparameter

Alternatively, if you are using python requests module, you can do

import requests
payload = {"do": "http://webpage.com/?secondary=parameter"}
r = requests.get("http://myserver.appspot.com/", params=payload)

which gives output

>>> print r.url
u'http://myserver.appspot.com/?do=http%3A%2F%2Fwebpage.com%2F%3Fsecondary%3Dparameter'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM