Thực hiện HTTP Request với Drupal
public
group: Vietnamese
thehong@drupal.org - Fri, 2007-08-24 16:04
Drupal cung cấp hàm drupal_http_request (dựa trên hàm [codefilter_code]fsockopen/codefilter_code của PHP) để code có thể dựa vào đó thực hiện các yêu cầu HTTP từ module.
Thực hiện GET request
Thí dụ 1 xuất ra nội dung HTML của trang chủ Google
<?php
$request = drupal_http_request('http://google.com');
print $request->data;
?>Thực hiện POST request
Thí dụ 2, thực hiện đăng nhập từ xa, hai khóa/giá trị cung cấp là username và password
<?php
$user = "MyUserName";
$password = "MyPassword";
$request = drupal_http_request(
'http://website.com/login.php',
array("Content-type" => "application/x-www-form-urlencoded"),
'POST',
"username=".drupal_urlencode($user)."&password=".drupal_urlencode($password);
);
?>Tham khảo thêm tại
:-)
Sổ tay Drupal: Phát triển module

