zoukankan      html  css  js  c++  java
  • PHP SOAP

    <?php
    $classmap = array();
    //注意和实例一的不同
    $soap = new SoapServer(null, array('uri' => "http://localhost", "classmap" => $classmap));
    $soap->setClass('Myclass');
    $soap->handle();
    class Myclass
    {
        function say($someword)
        {
            return $someword;
        }
    }
    ?>
    <?
    try {
        $client = new SoapClient(null, array('location' => "http://localhost/server.php",
                'uri' => "http://localhost"));
        //var_dump($client);
        echo $client->say("xyz world");
    }
    catch (SoapFault $fault) {
        echo "Error: ", $fault->faultcode, ", string: ", $fault->faultstring;
    }

    Internal Server Error

    表示服务器验证出错

    <?php
    
    // 服务器验证
    if ($_SERVER['PHP_AUTH_USER'] != 'bo' || $_SERVER['PHP_AUTH_PW'] != 'bo') {
        header('WWW-Authenticate: Basic realm="MyFramework Realm"');
        header('HTTP/1.0 401 Unauthorized');
        echo "You must enter a valid login ID and password to access this resource.
    ";
        exit;
    }
    
    require ("soapHandle.class.php"); // 处理请求的class
    
    try {
        $server = new SOAPServer(null, array('uri' => 'http://localhost/soap/server.php'));
        $server->setClass('soapHandle'); //设置处理的class
        $server->handle();
    }
    catch (SOAPFault $f) {
        print $f->faultString; // 打印出错信息
    }
    
    ?>
    <?php
    
    class soapHandle{
    
        public function strtolink($url=''){
            return sprintf('<a href="%s">%s</a>', $url, $url);
        }
    
    }
    
    ?>
    <?php
    
    try {
        $client = new SOAPClient(null, array(
            'location' => 'http://localhost/soap/server.php', // 设置server路径
            'uri' => 'http://localhost/soap/server.php',
            'login' => 'bo', // HTTP auth login
            'password' => 'bo' // HTTP auth password
                ));
    
        echo $client->strtolink('http://blog.csdn.net/fdipzone') . '<br>'; // 直接调用server方法
        echo $client->__soapCall('strtolink', array('http://blog.csdn.net/fdipzone')); // 间接调用server方法
    }
    catch (SOAPFault $e) {
        print $e->getMessage();
    }
    
    ?>

    <?php$classmap = array();//注意和实例一的不同$soap = new SoapServer(null, array('uri' => "http://localhost", "classmap" => $classmap));$soap->setClass('Myclass');$soap->handle();class Myclass{    function say($someword)    {        return $someword;    }}?>

  • 相关阅读:
    zt:HttpUrlConnection使用详解
    使用HttpUrlConnection访问www.163.com遇到503问题,用设置代理加以解决
    『TensorFlow』第十弹_队列&多线程_道路多坎坷
    『TensorFlow』项目资源分享
    『Python』socket网络编程
    『TensorFlow』第九弹_图像预处理_不爱红妆爱武装
    『TensorFlow』迁移学习
    『TensorFlow』函数查询列表_神经网络相关
    『TensorFlow』函数查询列表_张量属性调整
    『TensorFlow』函数查询列表_数值计算
  • 原文地址:https://www.cnblogs.com/ilookbo/p/5721876.html
Copyright © 2011-2022 走看看