php - 从 PHP 调用 Web 服务

标签 php drupal web-services

如何从 php 调用 web 服务

最佳答案

使用curl函数:

http://php.net/manual/en/book.curl.php

假设您使用 GET 请求连接到 RESTful API:

$url = "http://the-api-you-want/?the-args=your-args&another-arg=another-arg"; 
$ch = curl_init(); // start CURL
curl_setopt($ch, CURLOPT_URL, $url); // set your URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the response as a variable
$json = curl_exec($ch); // connect and get your JSON response 
curl_close($ch);

然后,您可以在响应中使用 PHP 的 json_decode,如果您想这样做的话。

另一种选择是使用 Drupal 的 drupal_http_request 函数 http://api.drupal.org/api/function/drupal_http_request/6

关于php - 从 PHP 调用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2707802/

相关文章:

c# - 如何获取从 web 服务请求返回的原始 xml?

php - 使用循环从多个 PHP 回显属性设置 CSS x 和 y

Drupal 7 次浏览 : Combine exposed filter with contextual filter?

php - 如何从 PHP 7 中的嵌套包含文件中跳出 while 循环?

drupal - 以编程方式在 Drupal 的文件系统中插入文件?

php - 与 openCPU 交互

c# - .NET 4.5 中的 WCF 不安全响应

c# - File.ReadAllText 线程安全吗?

php - ffmpeg 无法在 php exec() 中工作

javascript - 如何让.post打开一个url而不是生成html?