php获取curl发布的数据

时间:2012-03-22 09:38:39

标签: php curl

我通过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);

?>

1 个答案:

答案 0 :(得分:0)

如果您的意思是在php中获取POST数据,那么乍一看似乎是在发布单个字段c.setopt(pycurl.POSTFIELDS, "xml="+str(xmldata))

所以它应该是$_POST['xml']

如果你的意思是用curl作为响应读取数据,那么curl应该在执行时有returnntransfer选项(我不熟悉python语法)

相关问题