You are here

function _antispam_api_http_post in AntiSpam 7

Same name and namespace in other branches
  1. 6 antispam.module \_antispam_api_http_post()

Perform a HTTP POST request against the antispam server.

Parameters

string $request: The request.

string $host: The antispam host, prefixed with the API key (except when checking for the key itself).

string $path: The path where to perform the request.

Return value

array Headers in $response[0] and entity in $response[1].

4 calls to _antispam_api_http_post()
antispam_api_cmd_comment_check in ./antispam.module
AntiSpam API: Comment Check.
antispam_api_cmd_submit_ham in ./antispam.module
AntiSpam API: Submit Ham
antispam_api_cmd_submit_spam in ./antispam.module
AntiSpam API: Submit Spam
antispam_api_cmd_verify_key in ./antispam.module
AntiSpam API: Key Verification.

File

./antispam.module, line 2364
Primary hook implementations for the Antispam module.

Code

function _antispam_api_http_post($request, $host, $path) {
  $fsock_timeout = (int) variable_get('antispam_connection_timeout', 10);
  $http_request = "POST {$path} HTTP/1.0\r\n" . "Host: {$host}\r\n" . "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" . 'Content-Length: ' . strlen($request) . "\r\n" . 'User-Agent: ' . ANTISPAM_API_USERAGENT . "\r\n" . "\r\n" . $request;
  $response = '';
  if (false !== ($fs = @fsockopen($host, ANTISPAM_AKISMET_API_PORT, $errno, $errstr, $fsock_timeout))) {
    fwrite($fs, $http_request);
    while (!feof($fs)) {

      // One TCP-IP packet.
      $response .= fgets($fs, 1160);
    }
    fclose($fs);
    $response = explode("\r\n\r\n", $response, 2);
  }
  return $response;
}