Php curl 通过 SSL 作为 GET 方法或 Pt 方法发送 xml 文件

发布于 2024-11-17 14:40:19 字数 2576 浏览 3 评论 0原文

我需要从服务器接收 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文