我需要从服务器接收 xml 数据。只允许两种方法将数据发送到服务器“GET”和“PUT”POST 方法 - 不允许。
我的代码是
<?php
set_time_limit(0);
ini_set('display_errors','1');
error_reporting(E_ALL);
$url = 'https://url is here..';
$fp = fopen(getcwd() . "/ping.xml", "r+");
// Initialize session and set URL.
$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
curl_setopt($ch, CURLOPT_URL, $url);
//GET
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_FILE, $fp);
//curl_setopt($ch, CURLOPT_INFILE, $fp);
//curl_setopt($ch, CURLOPT_INFILESIZE, filesize(getcwd() . "/ping.xml"));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSLVERSION, 3 );
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "/certs/test_lv.pem");
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "test_lv");
curl_setopt($ch, CURLOPT_SSLKEY, getcwd() . "/certs/test_lv.key");
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "test_lv");
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','correlationId :'.date("y-m-d-h-m-s")));
curl_setopt($ch, CURLOPT_HEADER, 1);
// Get the response and close the channel.
$response = curl_exec($ch);
echo curl_error($ch);
print_r($response);
echo '<br>end';
curl_close($ch);
?>
我整天都在连接服务器,现在它可以工作了。我尝试将 xml 文件作为 Put 方法
Xml 文件数据发送:
<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>
它不起作用我有这个错误:
HTTP/1.1 100 继续 HTTP/1.1 500 内部服务器错误内容长度:0 服务器:码头(6.1.21)结束
答案需要是:
收到pong.xml-s
<?xml version="1.0" encoding="UTF-8"?>
<B4B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://test.net/valid/hgw-response.xsd">
<Pong from="EE">
<Value>Test</Value>
</Pong></B4B>
感谢您的建议
PS我如何通过GET方法发送xml文件..我正在尝试这样做
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>';
curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
这对我来说也不行。