用PHP创建Web服务 [英] Creating a web service in PHP

查看:50
本文介绍了用PHP创建Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PHP创建一个Web服务,供不同的使用者(网页,Android设备,iOS设备)使用.

I would like to create a web service in PHP which can be consumed by different consumers (Web page, Android device, iOS device).

我来自Microsoft背景,因此对在C#等程序中的操作方式感到很自在.理想情况下,我希望能够提供可以发送JSON的REST服务.

I come from a Microsoft background so am confortable in how I would do it in C# etc. Ideally I would like to be able to provide a REST service which can send JSON.

您能告诉我如何在PHP中实现吗?

Can you let me know how I can achieve this in PHP?

谢谢

Tariq

推荐答案

我开发了一个类,该类是PHP本机SoapServer类的REST等效项.

I developed a class that is the PHP native SoapServer class' REST equivalent.

您只需包含RestServer.php文件,然后按如下所示使用它即可.

You just include the RestServer.php file and then use it as follows.

class Hello
{
  public static function sayHello($name)
  {
    return "Hello, " . $name;
  }
}

$rest = new RestServer(Hello);
$rest->handle();

然后,您可以使用以下另一种语言拨打电话:

Then you can make calls from another language like this:

http://myserver.com/path/to/api?method=sayHello&name=World

(请注意,查询字符串中提供的参数的顺序无关紧要.而且,参数键名称和方法名称均不区分大小写.)

(Note that it doesn't matter what order the params are provided in the query string. Also, the param key names as well as the method name are case-insensitive.)

在此处获取.

这篇关于用PHP创建Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆