dsl2014 2011-07-21 08:14
浏览 47
已采纳

通过CURL发布XML文件而不是访问网址

While I am posting XML content from one server to other server, it is not getting added. I'm using cURL to post the xml files to another server. But I am getting the following response:

HTTP/1.1 200 OK
Date: Thu, 21 Jul 2011 08:13:02 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g
X-Powered-By: PHP/5.2.4-2ubuntu5.6
Set-Cookie: PHPSESSID=6846cb7e65f6f6d6d87f163a681f0543; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 5721
Content-Type: text/html; charset=UTF-8

This is my code

$file_path= WWW_ROOT.$xmlfilename;          
$xmldata = file_get_contents($file_path);
$request = 'http://www.sample.com/someaction';
$postargs = 'xml='.urlencode($xmldata).'&filename='.urlencode($xmlfilename);

// Get the curl session object
$session = curl_init($request);

// Set the POST options.
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Do the POST and then close the session
$response = curl_exec($session);
print_r( $response);

Note: allow_url_fopen and curl are enabled in both servers.

  • 写回答

1条回答 默认 最新

  • dsu5188 2011-07-21 08:18
    关注

    Try assigning it like this:

    $postargs = array('xml' => urlencode($xmldata), 'filename' => urlencode($xmlfilename))

    Both items should then appear in $_POST['xml'] and $_POST['filename'] in the receiving side (or equivalent if not PHP).

    EDIT

    OK you may need to look at streaming the XML file using CURLOPT_READFUNCTION.

    See this for a bit of an example http://zingaburga.com/2011/02/streaming-post-data-through-php-curl-using-curlopt_readfunction/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀