首页 >php教程 >php手册 >php fsockopen post数据发送实例

php fsockopen post数据发送实例

WBOY
WBOY原创
2016-06-02 09:14:071235浏览

<?php
function do_call($host, $port, $request) //定义函数
{
    $fp = fsockopen($host, $port, $errno, $errstr);
    $query = "post /default/php/server.php http/1.0nuser_agent:this is a dummy clientnhost:" . $host . "ncontent-type:text/xmlncontent-length:" . strlen($request) . "nn" . $request . "n";
    if (!fputs($fp, $query, strlen($query))) {
        $errstr = "write error";
        return 0;
    }
    $contents = &#39;&#39;;
    while (!feof($fp)) {
        $contents.= fgets($fp);
    }
    fclose($fp);
    return $contents;
}
$host = &#39;localhost&#39;; //定义host地址
$port = 80; //定义端口
$obj->type = "datetime"; //定义对象
$obj->scalar = "20040420t13:32:40";
$obj->timestamp = 1082460760;
$request = xmlrpc_encode_request(&#39;dummyserver&#39;, $obj); //为php生成xml
$response = do_call($host, $port, $request); //调用函数
$xmlrpctype = xmlrpc_get_type($response); //获取xmlrpc类型
print_r($xmlrpctype); //输出结果
?>


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn