从PHP调用Web服务

War*_*ior 3 php web-services drupal

我怎样才能从php调用Web服务

Fin*_*arr 5

使用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);
Run Code Online (Sandbox Code Playgroud)

然后,您可以json_decode在响应中使用PHP ,如果这是您想要做的.

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