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

祝你好运,我希望这有助于其他人

更多相关文章

  1. JSFiddle:无法从数据库加载Ajax数据
  2. Laravel将动态输入数据数组保存到数据库中
  3. 如何将多行数据插入到一个表字段中
  4. 如何将数据从MySQL表放入谷歌图表API?
  5. php使用openssl进行Rsa长数据加密(117)解密(128)
  6. Zend数据库适配器-未捕获异常-堆栈跟踪显示用户名和密码
  7. 在Cake PHP中更新现有的sql数据
  8. 在数据库中存储行数或动态获取
  9. 如何从databse中提取数据到2d数组中?

随机推荐

  1. yum怎么安装go语言
  2. go语言是动态语言么
  3. 详解golang string和[]byte的对比
  4. go属于动态语言么
  5. 关于go使用mysql测试
  6. go是强类型语言么
  7. 方便好用的Golang配置库(Viper)
  8. 总结Golang实现PHP常用函数
  9. go语言如何引入包
  10. 详解GoLang实现基于gin+jaeger的opentrac