如何使用drupal_http_request在Drupal中进行特定文件上载REST调用

时间:2018-01-21 09:06:02

标签: php drupal drupal-7

我想使用drupal_http_request将文件上传到另一个REST API,然后将结果解析为JSON。

我能够在Postman中为此生成一个“PHP客户端”,但它在Drupal中不起作用。这是它的样子:

$client = new http\Client;
$request = new http\Client\Request;

$request->setRequestUrl('https://api.cloudmersive.com/virus/scan/file');
$request->setRequestMethod('POST');
$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'apikey' => 'KEY_HERE'
));

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();

有两个问题 - 一,PostMan实际上并未添加上传文件的代码。其次,上面的代码不会在Drupal中运行,因为它正在进行不可用的引用,所以看起来我需要使用drupal_http_request函数。我很难弄清楚如何实际操作,因为我不太使用PHP。

关于如何仅使用内置的Drupal 7函数将文件实际发布到该端点的任何想法,例如: drupal_http_request?

0 个答案:

没有答案