我想获取已在请求中发送到服务器的引荐来源网址。我在 appengine 上使用 webapp2 框架。
当我做:
def post(self, slug):
print self.request
我得到以下输出:
OST /first/person/ HTTP/1.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Language: en-US,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Content-Length: 43 Content-Type: application/x-www-form-urlencoded Content_Length: 43 Content_Type: application/x-www-form-urlencoded Cookie: djdt=hide; csrftoken=09f29b2bfe9f51f16581bab7fe7c6f38; sessionid=49b995d954eae8d613cedc3f4e92a796 Host: 127.0.0.1:8080 Origin: http://127.0.0.1:8080 Referer: http://127.0.0.1:8080/person/1/
清晰可见Referer: http://127.0.0.1:8080/person/1/
我只对推荐人感兴趣,因此我尝试了:
referer = self.request.headers['Referer']
print referer
这给出了输出:
False Status: 200 Content-Type: text/html; charset=utf-8 Content-Length: 0 Cache-Control: no-cache
一种获取方法是根据请求进行字符串处理,但我相信会有更标准的东西。