我正在尝试用pyscripts/find_match.py编写一个Python脚本,它将处理upload.php页面中从POST接收到的数据,将其发送到connect.php,然后重定向到另一个php页面response.php,该页面将根据我处理的数据显示信息,并且具有<?php include '/connect_database.php';?>
行。
到目前为止,我能够获取POST信息,对其进行处理并通过JSON将其发送到connect.php,但是我无法将find_match.py重定向到response.php。我的代码如下:
在pyscripts/find_match.py中:print "Content-type: text/html"
print "
"print "
"import cgi
import cgitb
cgitb.enable()
try:
form = cgi.FieldStorage()
fn = form.getvalue('picture_name')
cat_id = form.getvalue('selected')
except KeyError:
print 'error'
else:
# code to process data here
data_to_be_displayed = # data to be used in connect.php; it's an array of ids
import httplib, json, urllib2
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
conn = httplib.HTTPConnection('192.168.56.101:80')
#converting list to a json stream
data_to_be_displayed = json.dumps(data_to_be_displayed, ensure_ascii = 'False')
conn.request("POST", "/connect_database.php", data_to_be_displayed, headers)
response = conn.getresponse()
text = response.read()
# print response.status, text
conn.close()
# WHAT I WANT TOT DO HERE
if response.status == 200:
redirect('/response.php')
print ""
在response.php中:
Response Page我找到了一些关于urllib.HTTPRequestHandler类和Location头的信息,但是我不知道如何使用它们。
尝试使用
在头牌上,但没用。
请帮忙。