使用php curl发送xml字符串但不作为post参数发送

时间:2013-01-17 13:31:36

标签: php curl https

:) 我正在尝试使用curl发送XML,但不是作为post参数发送。我的意思是这个。

例如。

该XML的接收方将无法使用$_POST变量接收XML。

他需要使用以下代码:

    $xmlStr=null;
    $file=fopen('php://input','r');
    $xmlStr=fgets($file);

我希望能够通过https使用curl发送一个xml字符串。

所以以下是错误的:

public static function HttpsNoVerify($url,$postFields=null,$verbose=false) {
    // Initialize session and set URL.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    // Set so curl_exec returns the result instead of outputting it.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    if ($postFields !=null) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    }
    if ($verbose) {
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
    }
    // Get the response and close the channel.
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

因为在这里我可以使用HttpsNoVerify($url,array('xml_file'=>'xml..')); 将它粘贴为post参数。我希望它作为后期输出。

所以,我希望我能正确解释自己,并且我完全解释了我不想做的事情。

我该怎么做我想做的事?

谢谢! :)

幼狮

1 个答案:

答案 0 :(得分:1)

直接将xml字符串作为第二个参数而不是关联数组项

传递
HttpsNoVerify($url, 'xml ..');

这最终会调用

curl_setopt($ch, CURLOPT_POSTFIELDS, "xml ...");

php://input放入远程服务器。