-2
的PythonPOST请求从Python来PHP
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']);
}
当我尝试打印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.
修复代码的缩进 –
您如何确定它已成功发送? – yakiang
@yakiang,因为当我硬编码?item ='something'&item2 ='something'时,它显示在php – CodeGuru