本文整理汇总了PHP中HTTP_Request::addPostData方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::addPostData方法的具体用法?PHP HTTP_Request::addPostData怎么用?PHP HTTP_Request::addPostData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::addPostData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save($data)
{
if (!$data['GA_optin']) {
trigger_error('did not opt to join');
return true;
}
$options = $this->getOptions();
$request = new HTTP_Request($options['hostname'] . '/offsite-join.tcl');
$request->setMethod(HTTP_REQUEST_METHOD_POST);
$request->addPostData('domain', $options['domain']);
if ($options['source']) {
$request->addPostData('source', $options['source']);
}
if ($options['update']) {
$request->addPostData('update', $options['update']);
}
foreach ($this->translate($data) as $name => $value) {
$request->addPostData($name, $value);
}
if (!PEAR::isError($request->sendRequest())) {
$message = trim($request->getResponseBody());
if ('OK' == $message) {
return true;
} else {
$this->ERROR = $message;
trigger_error($message);
return false;
}
}
}
示例2: SendTrackback
/**
* Send a trackback to a site
*
* @access public
* @param string $title Title of the Site
* @param string $excerpt The Excerpt
* @param string $permalink The Permalink to send
* @param array $to Where to send the trackback
*/
function SendTrackback($title, $excerpt, $permalink, $to)
{
$title = urlencode(stripslashes($title));
$excerpt = urlencode(stripslashes($excerpt));
$blog_name = urlencode(stripslashes($this->gadget->registry->fetch('site_name', 'Settings')));
$permalink = urlencode($permalink);
require_once PEAR_PATH . 'HTTP/Request.php';
$options = array();
$timeout = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings');
$options['timeout'] = $timeout;
if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') {
if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') {
$options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings');
$options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings');
}
$options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings');
$options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings');
}
$httpRequest = new HTTP_Request('', $options);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
foreach ($to as $url) {
$httpRequest->setURL($url);
$httpRequest->addPostData('title', $title);
$httpRequest->addPostData('url', $permalink);
$httpRequest->addPostData('blog_name', $blog_name);
$httpRequest->addPostData('excerpt', $excerpt);
$resRequest = $httpRequest->sendRequest();
$httpRequest->clearPostData();
}
}
示例3: sendNotification
function sendNotification($message, $regId)
{
$apikey = "AIzaSyDh3_C0r5OxdGGHN516XleJ1G_-aAMxEC4";
$rq = new HTTP_Request("https://android.googleapis.com/gcm/send");
$rq->setMethod(HTTP_REQUEST_METHOD_POST);
$rq->addHeader("Authorization", "key=" . $apikey);
$rq->addPostData("registration_id", $regId);
$rq->addPostData("collapse_key", "1");
$rq->addPostData("data.message", $message);
if (!PEAR::isError($rq->sendRequest())) {
print "\n" . $rq->getResponseBody();
} else {
print "\nError has occurred";
}
}
示例4: call
/**
* @throws BadRequestException
* @param $method
* @param $args
* @return mixed
*/
public function call($method, $args)
{
$req = new HTTP_Request($this->conf->endpoint . $method);
$req->setMethod('POST');
$args['app_id'] = $this->conf->app_id;
foreach ($args as $key => $value) {
$req->addPostData($key, $value);
}
$sig = sign($args, $this->conf->key);
$req->addPostData('signature', $sig['signature']);
$req->addPostData('time', $sig['time']);
$req->sendRequest();
if ($req->getResponseCode() != 200) {
throw new BadRequestException($req->getResponseBody());
}
return json_decode($req->getResponseBody());
}
示例5: addParams
function addParams($params = array())
{
if (!empty($params)) {
foreach (array_keys($params) as $k) {
$this->HttpRequest->addPostData($k, $params[$k]);
}
}
}
示例6: request
/**
* 配信サーバーへリクエストを送信する.
*
* @param string $mode
* @param array $arrParams 追加パラメーター.連想配列で渡す.
* @return string|object レスポンスボディ|エラー時にはPEAR::Errorオブジェクトを返す.
*/
function request($mode, $arrParams = array(), $arrCookies = array())
{
$objReq = new HTTP_Request();
$objReq->setUrl(OSTORE_URL . 'upgrade/index.php');
$objReq->setMethod('POST');
$objReq->addPostData('mode', $mode);
foreach ($arrParams as $key => $val) {
$objReq->addPostData($key, $val);
}
foreach ($arrCookies as $cookie) {
$objReq->addCookie($cookie['name'], $cookie['value']);
}
$e = $objReq->sendRequest();
if (PEAR::isError($e)) {
return $e;
} else {
return $objReq;
}
}
示例7: call
private function call($method, $args, $include_api_key = true)
{
$host = "rest.akismet.com";
if ($include_api_key) {
$host = "{$this->api_key}.{$host}";
}
$url = "http://{$host}/1.1/{$method}";
$req = new HTTP_Request($url, array("method" => "POST"));
$req->addHeader("User-Agent", "Cyberspace-Networks/" . PA_VERSION);
foreach ($args as $k => $v) {
$req->addPostData($k, $v);
}
$req->sendRequest();
return $req->getResponseBody();
}
示例8: Post
/**
* Post data to TypePad api server
*
* @access public
*/
function Post($method, $params, $apiKey = '')
{
$path = "/{$this->apiVersion}/{$method}";
if ($apiKey == '') {
$host = $this->apiServer;
} else {
$host = $apiKey . '.' . $this->apiServer;
}
$url = sprintf('http://%s:%s/%s/%s', $host, $this->apiPort, $this->apiVersion, $method);
require_once PEAR_PATH . 'HTTP/Request.php';
$options = array();
$timeout = (int) $GLOBALS['app']->Registry->fetch('connection_timeout', 'Settings');
$options['timeout'] = $timeout;
if ($GLOBALS['app']->Registry->fetch('proxy_enabled', 'Settings') == 'true') {
if ($GLOBALS['app']->Registry->fetch('proxy_auth', 'Settings') == 'true') {
$options['proxy_user'] = $GLOBALS['app']->Registry->fetch('proxy_user', 'Settings');
$options['proxy_pass'] = $GLOBALS['app']->Registry->fetch('proxy_pass', 'Settings');
}
$options['proxy_host'] = $GLOBALS['app']->Registry->fetch('proxy_host', 'Settings');
$options['proxy_port'] = $GLOBALS['app']->Registry->fetch('proxy_port', 'Settings');
}
$httpRequest = new HTTP_Request('', $options);
$httpRequest->setURL($url);
$httpRequest->addHeader('User-Agent', $this->userAgent);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
foreach ($params as $key => $data) {
$httpRequest->addPostData($key, urlencode(stripslashes($data)));
}
$resRequest = $httpRequest->sendRequest();
if (PEAR::isError($resRequest)) {
return new Jaws_Error($resRequest->getMessage());
} elseif ($httpRequest->getResponseCode() != 200) {
return new Jaws_Error('HTTP response error ' . $httpRequest->getResponseCode(), 'Policy', JAWS_ERROR_ERROR);
}
return $httpRequest->getResponseBody();
}
示例9: while
}
}
}
if ($send_email) {
$send_mail =& $header;
$send_mail .= $body;
while (!feof(STDIN)) {
$a = fread(STDIN, 8192);
if (false !== strpos($a, "\r")) {
$a = strtr(str_replace("\r\n", "\n", $a), "\r", "\n");
}
$send_mail .= $a;
}
}
if (ini_get_bool('allow_url_fopen')) {
foreach ($notify_urls as &$a) {
$context = stream_context_create(array('http' => array('method' => 'POST', 'content' => http_build_query(array('event' => $event, 'inside-to' => $a['inside-to'], 'inside-references' => $a['inside-references'], 'email-body' => $send_email)))));
file_get_contents($a['notify_url'], false, $context);
}
} else {
require_once 'HTTP/Request.php';
foreach ($notify_urls as &$a) {
$r = new HTTP_Request($a['notify_url']);
$r->setMethod(HTTP_REQUEST_METHOD_POST);
$r->addPostData('event', $event);
$r->addPostData('inside-to', $a['inside-to']);
$r->addPostData('inside-references', $a['inside-references']);
$r->addPostData('email-body', $send_email);
$r->sendRequest();
}
}
示例10: chr
/**
* send the given XML to the server as configured in
* CSHOP_GIFTCARD_POST_URL. Remove some cruft from the response and return
* a XML string
*
* @private
* @param $xmlstr str some stuff to send
* @return str
*/
function _send_request($xmlstr)
{
$this->log("send_request(): {$xmlstr}");
$hr = new HTTP_Request(CSHOP_GIFTCARD_POST_URL);
$hr->setMethod(HTTP_REQUEST_METHOD_POST);
$hr->addPostData('Auth_Request', $xmlstr, true);
$req =& $hr->sendRequest();
if (PEAR::isError($req)) {
return $this->raiseError("Could not send request to giftcard processor gateway: " . $req->getMessage());
} else {
$res = $hr->getResponseBody();
$this->log("response: {$res}");
/* STS sends the XML wrapped in some HTML and control chars and other nonsense
* remove the cruft: */
preg_match("/" . chr(2) . "(.*)" . chr(3) . "/", $res, $m);
return $m[1];
}
}
示例11: post
/**
* Posts data to the URL
*
* @access public
* @param string $url URL address
* @param array $params Associated name/data values
* @param string $response Response body
* @return mixed Response code on success, otherwise Jaws_Error
*/
function post($url, $params = array(), &$response)
{
$httpRequest = new HTTP_Request($url, $this->options);
$httpRequest->addHeader('User-Agent', $this->user_agent);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
// add post data
foreach ($params as $key => $data) {
$httpRequest->addPostData($key, urlencode($data));
}
$result = $httpRequest->sendRequest();
if (PEAR::isError($result)) {
return Jaws_Error::raiseError($result->getMessage(), $result->getCode(), $this->default_error_level, 1);
}
$response = $httpRequest->getResponseBody();
return $httpRequest->getResponseCode();
}
示例12: akismetRequest
function akismetRequest($api_key, $data, &$ret, $action = 'comment-check', $eventData = null, $addData = null)
{
global $serendipity;
$opt = array('method' => 'POST', 'http' => '1.1', 'timeout' => 20, 'allowRedirects' => true, 'maxRedirects' => 3, 'readTimeout' => array(5, 0));
// Default server type to akismet, in case user has an older version of the plugin
// where no server was set
$server_type = $this->get_config('akismet_server', 'akismet');
$server = '';
$anon = false;
switch ($server_type) {
case 'anon-tpas':
$anon = true;
case 'tpas':
$server = 'api.antispam.typepad.com';
break;
case 'anon-akismet':
$anon = true;
case 'akismet':
$server = 'rest.akismet.com';
break;
}
if ($anon) {
$data['comment_author'] = 'John Doe';
$data['comment_author_email'] = '';
$data['comment_author_url'] = '';
}
if (empty($server)) {
$this->log($this->logfile, is_null($eventData) ? 0 : $eventData['id'], 'AKISMET_SERVER', 'No Akismet server found', $addData);
$ret['is_spam'] = false;
$ret['message'] = 'No server for Akismet request';
return;
} else {
// DEBUG
//$this->log($this->logfile, $eventData['id'], 'AKISMET_SERVER', 'Using Akismet server at ' . $server, $addData);
}
$req = new HTTP_Request('http://' . $server . '/1.1/verify-key', $opt);
$req->addPostData('key', $api_key);
$req->addPostData('blog', $serendipity['baseURL']);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$ret['is_spam'] = false;
$ret['message'] = 'API Verification Request failed';
$this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet HTTP verification request failed.', $addData);
return;
} else {
// Fetch response
$reqdata = $req->getResponseBody();
}
if (!preg_match('@valid@i', $reqdata)) {
$ret['is_spam'] = false;
$ret['message'] = 'API Verification failed';
$this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API verification failed: ' . $reqdata, $addData);
return;
}
$req = new HTTP_Request('http://' . $api_key . '.' . $server . '/1.1/' . $action, $opt);
foreach ($data as $key => $value) {
$req->addPostData($key, $value);
}
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$ret['is_spam'] = false;
$ret['message'] = 'Akismet Request failed';
$this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet HTTP request failed.', $addData);
return;
} else {
// Fetch response
$reqdata = $req->getResponseBody();
}
if ($action == 'comment-check' && preg_match('@true@i', $reqdata)) {
$ret['is_spam'] = true;
$ret['message'] = $reqdata;
// DEBUG
//$this->log($this->logfile, $eventData['id'], 'AKISMET_SPAM', 'Akismet API returned spam', $addData);
} elseif ($action == 'comment-check' && preg_match('@false@i', $reqdata)) {
$ret['is_spam'] = false;
$ret['message'] = $reqdata;
// DEBUG
//$this->log($this->logfile, $eventData['id'], 'AKISMET_PASS', 'Passed Akismet verification', $addData);
} elseif ($action != 'comment-check' && preg_match('@received@i', $reqdata)) {
$ret['is_spam'] = $action == 'submit-spam';
$ret['message'] = $reqdata;
$this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API failure: ' . $reqdata, $addData);
} else {
$ret['is_spam'] = false;
$ret['message'] = 'Akismet API failure';
$this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API failure: ' . $reqdata, $addData);
}
}
示例13: request
static function request($method, $url, $token = null, $params = array(), $file = null)
{
$req = new HTTP_Request($url);
$req->setMethod($method == "get" ? HTTP_REQUEST_METHOD_GET : HTTP_REQUEST_METHOD_POST);
$req->addHeader("X-Gallery-Request-Method", $method);
if ($token) {
$req->addHeader("X-Gallery-Request-Key", $token);
}
foreach ($params as $key => $value) {
$req->addPostData($key, $value);
}
if ($file) {
$req->addFile("file", $file, mime_content_type($file));
}
$req->sendRequest();
switch ($req->getResponseCode()) {
case 200:
return json_decode($req->getResponseBody());
case 403:
throw new Gallery3_Forbidden_Exception($req->getResponseBody());
default:
throw new Gallery3_Exception($req->getResponseBody());
}
}
示例14: resend_request
/**
* Re-send a request after successful re-authentication
*
* Re-creates a GET or POST request based on data passed along in a form. Used
* in case of an expired security token so that the user doesn't lose changes.
*
*/
function resend_request()
{
global $_CONF;
require_once 'HTTP/Request.php';
$method = '';
if (isset($_POST['token_requestmethod'])) {
$method = COM_applyFilter($_POST['token_requestmethod']);
}
$returnurl = '';
if (isset($_POST['token_returnurl'])) {
$returnurl = urldecode($_POST['token_returnurl']);
if (substr($returnurl, 0, strlen($_CONF['site_url'])) != $_CONF['site_url']) {
// only accept URLs on our site
$returnurl = '';
}
}
$postdata = '';
if (isset($_POST['token_postdata'])) {
$postdata = urldecode($_POST['token_postdata']);
}
$getdata = '';
if (isset($_POST['token_getdata'])) {
$getdata = urldecode($_POST['token_getdata']);
}
$files = '';
if (isset($_POST['token_files'])) {
$files = urldecode($_POST['token_files']);
}
if (SECINT_checkToken() && !empty($method) && !empty($returnurl) && ($method == 'POST' && !empty($postdata) || $method == 'GET' && !empty($getdata))) {
$magic = get_magic_quotes_gpc();
$req = new HTTP_Request($returnurl);
if ($method == 'POST') {
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$data = unserialize($postdata);
foreach ($data as $key => $value) {
if ($key == CSRF_TOKEN) {
$req->addPostData($key, SEC_createToken());
} else {
if ($magic) {
$value = stripslashes_gpc_recursive($value);
}
$req->addPostData($key, $value);
}
}
if (!empty($files)) {
$files = unserialize($files);
}
if (!empty($files)) {
foreach ($files as $key => $value) {
$req->addPostData('_files_' . $key, $value);
}
}
} else {
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$data = unserialize($getdata);
foreach ($data as $key => $value) {
if ($key == CSRF_TOKEN) {
$req->addQueryString($key, SEC_createToken());
} else {
if ($magic) {
$value = stripslashes_gpc_recursive($value);
}
$req->addQueryString($key, $value);
}
}
}
$req->addHeader('User-Agent', 'Geeklog/' . VERSION);
// need to fake the referrer so the new token matches
$req->addHeader('Referer', COM_getCurrentUrl());
foreach ($_COOKIE as $cookie => $value) {
$req->addCookie($cookie, $value);
}
$response = $req->sendRequest();
if (PEAR::isError($response)) {
if (!empty($files)) {
SECINT_cleanupFiles($files);
}
trigger_error("Resending {$method} request failed: " . $response->getMessage());
} else {
COM_output($req->getResponseBody());
}
} else {
if (!empty($files)) {
SECINT_cleanupFiles($files);
}
echo COM_refresh($_CONF['site_url'] . '/index.php');
}
// don't return
exit;
}
示例15: getHttpResponse
/**
* Return array contains the response of the given URL.
* array[code] => HTTP status code
* array[headers] => HTTP headers
* array[headers] => Entity body
* Throw exception if error.
*
* @param string $url
* @param array $headers
* @param array $post
* @return array
*/
private function getHttpResponse($url, $headers = array(), $post = array())
{
$url = str_replace('&', '&', trim($url));
$req = new HTTP_Request($url, array('allowRedirects' => true, 'maxRedirects' => 5));
/*
* @see HTTP_Request_Listener_Extended
*/
$listener = new HTTP_Request_Listener_Extended();
$req->attach($listener);
if (!isset($headers['user-agent'])) {
$headers['user-agent'] = $this->httpUserAgent;
}
foreach ($headers as $key => $value) {
if (!empty($value)) {
$req->addHeader($key, $value);
}
}
if (!empty($post)) {
$req->setMethod('POST');
foreach ($post as $key => $value) {
$req->addPostData($key, $value);
}
}
$result = $req->sendRequest();
$is_error = false;
if (PEAR::isError($result)) {
$is_error = true;
$error_message = $result->getMessage();
/*
* $error_message could be empty if the error was raised
* when fsockopen() returns false in Net_Socket::connect()
*/
if (empty($error_message)) {
$error_message = "Failed connecting to the server.";
/*
* HTTP_Request raises 'Malformed response' error
* if request path is empty (e.g. http://www.example.com).
* This bug still exists in its automatic redirection mechanism
* in CVS rev. 1.55 (latest as of May 18, 2007).
*/
} elseif ($error_message == 'Malformed response.') {
$url = $req->getURL(null);
if (false !== ($urls = @parse_url($url)) and !isset($urls['path'])) {
$req->setURL($url);
$result = $req->sendRequest();
if (PEAR::isError($result)) {
$error_message = $result->getMessage();
if (empty($error_message)) {
$error_message = "Failed connecting to the server.";
}
} else {
$is_error = false;
}
}
}
}
if ($is_error) {
throw new Exception($error_message);
}
return array('url' => $req->getUrl(null), 'code' => $req->getResponseCode(), 'headers' => $req->getResponseHeader(), 'body' => $req->getResponseBody());
}