【问题标题】:Post Parameter to other Server将参数发布到其他服务器
【发布时间】:2016-04-14 16:49:49
【问题描述】:

我想用 php curl 将参数发送到一个 api。内容类型是 xml,但是当我发送这个参数时,我得到了一个错误:

Notice: Use of undefined constant CURLOPT_MUTE - assumed 'CURLOPT_MUTE' in C:\xampp\htdocs\router.php on line 20

Warning: curl_setopt() expects parameter 2 to be long, string given in C:\xampp\htdocs\router.php on line 20

我的 curl 代码是:

$xml_data ='<?xml version="1.0" encoding="utf-8"?>'.
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
    '<soap:Body>'.
    '<getMassBarcode xmlns="http://tempuri.org/">'.
    '<UserName>username</UserName>'.
    '<Password>password</Password>'.
'<PostNodeCode>19387</PostNodeCode>'.
'<CityCode>1</CityCode>'.
    '<TypeCode>11</TypeCode>'.
    '</getMassBarcode>'.
'</soap:Body>'.
'</soap:Envelope>';


$URL = "http://poffice.post.ir/webbarcode/getbarcode.asmx";

        $ch = curl_init($URL);
        curl_setopt($ch, CURLOPT_MUTE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        curl_close($ch);

我该如何解决这个问题?

注意:我使用 post man 来测试那个 api。在邮递员原始选项中,我放置了那个 xml 内容。效果很好

【问题讨论】:

    标签: php curl xampp


    【解决方案1】:

    您可能正在使用更高版本的 curl。刚刚从代码中删除了该行,它应该对你有用。

    来自curl setopt 页面:

    在 cURL 7.15.5 中删除(您可以改用 CURLOPT_RETURNTRANSFER)

    【讨论】:

    • 我删除了curl_setopt($ch, CURLOPT_MUTE, 1); 但不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2017-05-10
    • 2021-02-19
    • 2015-07-28
    相关资源
    最近更新 更多