Php curl 通过 SSL 作为 GET 方法或 Pt 方法发送 xml 文件
我需要从服务器接收 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 服务器:Jetty(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>
感谢您的建议
P.S 我如何通过 GET 方法发送 xml 文件..我正在尝试这样做,
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>';
curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
这对我来说也不起作用。
I need to receive xml data from server.
Allowed only two methods to send data to server "GET" AND "PUT"
POST method- is no allowed.
My code is
<?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);
?>
I have spent all my day connecting to the server and now it works.
I trying to send xml file as Put method
Xml file data:
<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>
Its not work I have this error:
HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Content-Length: 0 Server: Jetty(6.1.21)
end
Answers needs to be:
Received 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>
Thanks for advices
P.S How can i Send xml file via GET method ..Im trying to do this
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>';
curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
It's not work too for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论