【问题标题】:repost xml postback to another url将 xml 回发重新发布到另一个 url
【发布时间】:2016-04-11 14:17:20
【问题描述】:

我们目前正在使用 Ultracart 将 xml 回发到我们服务器上的 url。我想要做的是接收那个xml,然后右转并将其发布到另一个页面。 (我们在为我们正在进行的项目向多个来源发送回传时遇到问题。)这是我一直在玩的:

$xml = file_get_contents('php://input');
$url = 'https://destinationlink';


$post_data = array(
    "xml" => $xml,
);

$stream_options = array(
    'http' => array(
       'method'  => 'POST',
       'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
       'content' => http_build_query($post_data),
    ),
);
$context  = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);

我知道我在这里遗漏了一些重要的东西......我想我已经看得太久了,我看不出问题......可能是一些简单得愚蠢的东西。

【问题讨论】:

    标签: php xml postback


    【解决方案1】:

    原来 CURL 是这里的答案。

    //URL where to send the data via POST
    $URL1 = 'http://destinationlink';
    
    //the actual data
    $xml_data1 = file_get_contents('php://input');
    
    
        $ch1 = curl_init($URL1);
        curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch1, CURLOPT_POST, 1);
        curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch1, CURLOPT_POSTFIELDS, "$xml_data1");
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
        $output1 = curl_exec($ch1);
        curl_close($ch1);
    

    这就像一个魅力。

    我可以接收 XML 回发 (php://input),使用此 curl 代码根据目标 URL 制作不同的块,并将信息一一发送到我需要的所有单独连接。

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2016-06-26
      • 1970-01-01
      • 2015-08-13
      相关资源
      最近更新 更多