php webservice 驗證 另一方式

來源:互聯網
上載者:User

這是csdn 的文章內容 自己留著了 感覺這種方式不太正規 但可用

client_1.php

<?php<br />$re=$soapClient = new SoapClient("http://test.cheshi.com/webservice/server_1.php?wsdl",array("login"=>"admin","password"=>"123456"));</p><p>echo $soapClient->hw('hello','world');<br />?>

server_1.php

<?php<br />error_reporting(2047);<br />ini_set("soap.wsdl_cache_enabled", "0");<br />if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||<br />!($_SERVER['PHP_AUTH_USER']=='admin' && $_SERVER['PHP_AUTH_PW']=='123456')) {<br /> header('WWW-Authenticate: Basic realm="WEBSERVICE"');<br /> header("HTTP/1.0 401 Unauthorized");<br /> echo "You must enter a valid login ID and password to access this resource/n";<br /> die;<br />}<br />class serverClass<br />{<br /> function hw($name,$pass)<br /> {<br /> return $name." ".$pass;<br /> }<br />}<br />$soapServer = new SoapServer("hello.wsdl");<br />$soapServer->setClass('serverClass');<br />$soapServer->handle();</p><p>?>

hello.wsdl

<?xml version ='1.0' encoding ='UTF-8' ?><br /><definitions name='lake' targetNamespace='http://test.cheshi.com/webservice/' xmlns:tns='http://test.cheshi.com/webservice/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'></p><p><message name='getRequest'><br /> <part name='name' type='xsd:string'/><br /> <part name='pass' type='xsd:string'/><br /></message></p><p><message name='getResponse'></p><p> <part name='Result' type='xsd:string'/><br /></message></p><p><portType name='class'><br /><operation name='hw'><br /> <input message='tns:getRequest'/><br /> <output message='tns:getResponse'></output><br /></operation><br /></portType></p><p><binding name='class' type='tns:class'><br /> <soap:binding style="rpc" mce_style="rpc" transport='http://schemas.xmlsoap.org/soap/http'/><br /> <operation name='hw'><br /> <soap:operation soapAction=''/><br /> <input><br /> <soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/><br /> </input><br /> <output><br /> <soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /><br /> </output><br /> </operation><br /></binding></p><p><service name='class'><br /> <port name='goforsoap' binding='class'><br /> <soap:address location='http://test.cheshi.com/webservice/server_1.php'/><br /> </port><br /></service><br /></definitions>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.