Python
params = urllib.parse.urlencode({'spam': '1', 'eggs': '2', 'bacon': '3'})
binary_data = params.encode('utf-8')
reg = urllib.request.Request("http://www.abc.com/abc/smart/ap/request/",binary_data)
reg.add_header('Content-Type','application/x-www-form-urlencoded')
f = urllib.request.urlopen(reg)
print(f.read())
PHP
if($_SERVER['REQUEST_METHOD'] == 'POST') {
//parse_str($_SERVER['QUERY_STRING']);
var_dump($_SERVER['QUERY_STRING']);
}
当我尝试 print binary_data 时,它确实显示了参数,但是当它到达 PHP 时,我什么也看不到。
任何想法?
编辑**
我只是做了更多的测试,如果我做一个
urllib.request.Request("http://www.abc.com/abc/smart/ap/request/?item='test'",binary_data)
the parameter, item , does get sent to php.