php php网络服务示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4242355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php web service example
提问by Miya
I am new to web services. I would like to get a good tutorial and example for web service using PHP. Please suggest to me some websites that explain these things in a simple way.
我是网络服务的新手。我想获得一个很好的教程和使用 PHP 的 Web 服务示例。请向我推荐一些以简单方式解释这些事情的网站。
Thank you...
谢谢...
采纳答案by bcosca
Here are some links to get you started:
以下是一些可帮助您入门的链接:
http://davidwalsh.name/web-service-php-mysql-xml-json
http://davidwalsh.name/web-service-php-mysql-xml-json
http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/
http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/
回答by Bogdan Ciocoiu
This is what you need.
这就是你所需要的。
Make sure you habe Zend Framework installed - it says how to install it if you don't have it, anyway.
确保你已经安装了 Zend Framework - 无论如何,它会说明如果你没有它,如何安装它。
The good thing about it is that it allows Discovery - the rest of the tutorials on the net don't are basic POST/GET - no discovery of services.
关于它的好处是它允许发现 - 网络上的其余教程不是基本的 POST/GET - 没有服务发现。
<?php
ini_set('include_path', '/usr/share/php/libzend-framework-php/');
require_once 'Zend/Soap/AutoDiscover.php';
require_once "Zend/Soap/Server.php";
class BogdansInjectData {
private $quotes = array(
"one" => "answer one");
/**
* @param string $quote
* @return string
*/
function PushData($quote) {
/* just encase the string is in uppercase*/
$symbol = strtolower($quote);
/* if there is a quote for the day requested */
if (isset($this->quotes[$quote])) {
return $this->quotes[$quote];
} else {
/* else error */
throw new SoapFault("Server","Unknown Symbol '$quote'.");
}
}
}
// if(isset($_GET['wsdl'])) {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('BogdansInjectData');
$autodiscover->handle();
?>
Thanks, Bogdan
谢谢,博格丹
PS: Follow this post as it's the source for the solution and it's constantly updated: http://www.getcomputerservices.co.uk/web-development/php-web-service-with-microsoft-discovery/
PS:请关注这篇文章,因为它是解决方案的来源,并且会不断更新:http: //www.getcomputerservices.co.uk/web-development/php-web-service-with-microsoft-discovery/
回答by dreeves
Here's a simple example that may help you get started:
这是一个可以帮助您入门的简单示例:
https://stackoverflow.com/questions/502547/restful-webservice-to-sum-a-list-of-numbers
https://stackoverflow.com/questions/502547/restful-webservice-to-sum-a-list-of-numbers
And here's a slightly more complicated example:
这是一个稍微复杂的例子:
Php webservice that takes JSON via POST and spits back an image
回答by Julian
I use this source code. Its a SOAP example: http://www.java2s.com/Code/Php/Web-Services-SOAP-WSDL/CatalogWeb-Services-SOAP-WSDL.htm
我使用这个源代码。它是一个 SOAP 示例:http: //www.java2s.com/Code/Php/Web-Services-SOAP-WSDL/CatalogWeb-Services-SOAP-WSDL.htm