我通过curl调用php api。
ncServerURL='http://myserver/acertify.php'
# binaryptr = open('sampleamex.xml','rb').read()
# print binaryptr
c = pycurl.Curl()
c.setopt(pycurl.URL, ncServerURL)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
header=["Content-type: text/xml","SOAPAction:run",'Content-Type: text/xml; charset=utf-8','Content-Length: '+str(len(xmldata))]
# print header
c.setopt(pycurl.HTTPHEADER, header)
c.setopt(pycurl.POSTFIELDS, "xml="+str(xmldata))
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
ncServerData = b.getvalue()
return ncServerData以及发布xml数据。在acertify.php中,我不能在php文件中xml数据,我正在做一个项目,我不知道在这个项目中,我怎样才能在这个文件中获得curl发布的数据。
<?php
echo "hi";
print_r($_SESSION);
print_r($_POST);
// print_r($_FILES);
?>发布于 2012-03-22 17:41:22
如果你的意思是在php中获取帖子数据,那么乍一看你就像是在张贴一个字段c.setopt(pycurl.POSTFIELDS, "xml="+str(xmldata))。
所以它应该只是$_POST['xml']
如果您的意思是使用curl作为响应来读取数据,那么curl应该在执行时具有returntransfer选项(我不熟悉python语法)
https://stackoverflow.com/questions/9819636
复制相似问题