使用Python中的POST将数据发送到PHP
PHP code:
<?php
$data=$_POST['data'];
echo $data;
?>
When I do that, the HTML page that Python prints notifies me that PHP did not receive any value in $data
I.e:
当我这样做时,Python打印的HTML页面通知我PHP在$ data I.e中没有收到任何值:
Error in $name; undefined index
$ name错误;未定义的索引
However, when I send the data as GET (http://localhost/mine.php?data=data
) and change the PHP method from POST to GET ($data=$_GET['data']
), the value is gotten and processed.
但是,当我将数据作为GET(http://localhost/mine.php?data = data)发送并将PHP方法从POST更改为GET($ data = $ _ GET ['data'])时,获取的值为并加工。
My main issue here is that it seems the value in data does not go through to PHP as I would have wanted to use POST. What could be wrong?
我的主要问题是,似乎数据中的值没有通过PHP,因为我本想使用POST。可能有什么不对?
3 个解决方案
#1
31
Look at this python:
看看这个python:
import urllib2, urllib
mydata=[('one','1'),('two','2')] #The first is the var name the second is the value
mydata=urllib.urlencode(mydata)
path='http://localhost/new.php' #the url you want to POST to
req=urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
page=urllib2.urlopen(req).read()
print page
Almost everything was right there Look at line 2
几乎一切都在那里看第2行
heres the PHP:
继承人PHP:
<?php
echo $_POST['one'];
echo $_POST['two'];
?>
this should give you
这应该给你
1
2
Good luck and I hope this helps others
祝你好运,我希望这有助于其他人
更多相关文章
- JSFiddle:无法从数据库加载Ajax数据
- Laravel将动态输入数据数组保存到数据库中
- 如何将多行数据插入到一个表字段中
- 如何将数据从MySQL表放入谷歌图表API?
- php使用openssl进行Rsa长数据加密(117)解密(128)
- Zend数据库适配器-未捕获异常-堆栈跟踪显示用户名和密码
- 在Cake PHP中更新现有的sql数据
- 在数据库中存储行数或动态获取
- 如何从databse中提取数据到2d数组中?