Heim  >  Artikel  >  php教程  >  Drupal通过cURL Post方式发送一个文件

Drupal通过cURL Post方式发送一个文件

WBOY
WBOYOriginal
2016-06-06 20:11:161280Durchsuche

众所周知PHP的cURL扩展可以用来模拟表单提交。在Drupal中有 drupal_http_request 函数来执行一个HTTP请求,它可以通过POST方式来发送一个文件,但是使用起来没有cURL那么方便。 这里我们主要讲解如何在Drupal中Post一个文件到远程的服务器地址。 网页Form表

众所周知PHP的cURL扩展可以用来模拟表单提交。在Drupal中有drupal_http_request函数来执行一个HTTP请求,它可以通过POST方式来发送一个文件,但是使用起来没有cURL那么方便。 这里我们主要讲解如何在Drupal中Post一个文件到远程的服务器地址。

网页Form表单






上面表单包含了演示文本框、密码、复选框和文件形式的提交。

Drupal cURL模拟表单提交POST

$url = ‘http://blog.lixiphp.com/demo/http_request/post.php’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
‘username’ => ‘lixiphp’,
‘password’ => ’123456′,
‘rememberme’ => ’1′,
‘avatar’=> ‘@’.$filename,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);

$response的值为网页Form表单提交后输出的HTML。

(...)
Read the rest of Drupal通过cURL Post方式发送一个文件 (1 words)


© Li Xi for LixiPHP, 2013. | Permalink | No comment | Add to del.icio.us
Post tags: curl, drupal, drupal_http_request, Form, Post, 发送文件, 提交表单, 模拟表单

Feed enhanced by Better Feed from Ozh

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn