本文整理汇总了PHP中Piwik\Http::sendHttpRequestBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::sendHttpRequestBy方法的具体用法?PHP Http::sendHttpRequestBy怎么用?PHP Http::sendHttpRequestBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Http
的用法示例。
在下文中一共展示了Http::sendHttpRequestBy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendSMS
public function sendSMS($apiKey, $smsText, $phoneNumber, $from)
{
$account = explode(" ", $apiKey);
$parameters = array('user' => $account[0], 'pass' => $account[1], 'msg' => $smsText);
$url = self::API_URL . '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
$result = Http::sendHttpRequestBy(Http::getTransportMethod(), $url, $timeout, $getExtendedInfo = true);
}
示例2: testHEADOperation
/**
* @group Core
*
* @dataProvider getMethodsToTest
*/
public function testHEADOperation($method)
{
if ($method == 'fopen') {
return;
// not supported w/ this method
}
$result = Http::sendHttpRequestBy($method, 'http://builds.piwik.org/latest.zip', 30, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = false, $byteRange = false, $getExtendedInfo = true, $httpMethod = 'HEAD');
$this->assertEquals('', $result['data']);
$this->assertEquals(200, $result['status']);
$this->assertTrue(isset($result['headers']['Content-Length']), "Content-Length header not set!");
$this->assertTrue(is_numeric($result['headers']['Content-Length']), "Content-Length header not numeric!");
$this->assertEquals('application/zip', $result['headers']['Content-Type']);
}
示例3: issueApiCall
private function issueApiCall($apiKey, $resource, $additionalParameters = array())
{
$accountParameters = array('Key' => $apiKey);
$parameters = array_merge($accountParameters, $additionalParameters);
$url = self::BASE_API_URL . $resource . '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$result = Http::sendHttpRequestBy(Http::getTransportMethod(), $url, $timeout, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = true);
} catch (Exception $e) {
$result = self::ERROR_STRING . " " . $e->getMessage();
}
if (strpos($result, self::ERROR_STRING) !== false) {
throw new APIException('Clockwork API returned the following error message : ' . $result);
}
return $result;
}
示例4: checkPiwikServerWorking
/**
* Returns true if the Piwik server appears to be working.
*
* If the Piwik server is in an error state (eg. some directories are not writable and Piwik displays error message),
* or if the Piwik server is "offline",
* this will return false..
*
* @param $piwikServerUrl
* @param bool $acceptInvalidSSLCertificates
* @throws Exception
* @return bool
*/
public static function checkPiwikServerWorking($piwikServerUrl, $acceptInvalidSSLCertificates = false)
{
// Now testing if the webserver is running
try {
$fetched = Http::sendHttpRequestBy('curl', $piwikServerUrl, $timeout = 45, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSSLCertificates);
} catch (Exception $e) {
$fetched = "ERROR fetching: " . $e->getMessage();
}
// this will match when Piwik not installed yet, or favicon not customised
$expectedStringAlt = 'plugins/CoreHome/images/favicon.ico';
// this will match when Piwik is installed and favicon has been customised
$expectedString = 'misc/user/';
// see checkPiwikIsNotInstalled()
$expectedStringAlreadyInstalled = 'piwik-is-already-installed';
$expectedStringNotFound = strpos($fetched, $expectedString) === false && strpos($fetched, $expectedStringAlt) === false && strpos($fetched, $expectedStringAlreadyInstalled) === false;
$hasError = false !== strpos($fetched, PAGE_TITLE_WHEN_ERROR);
if ($hasError || $expectedStringNotFound) {
throw new Exception("\nPiwik should be running at: " . $piwikServerUrl . " but this URL returned an unexpected response: '" . $fetched . "'\n\n");
}
}
示例5: executeNotAsyncHttp
private function executeNotAsyncHttp($url, Output $output)
{
try {
Log::debug("Execute HTTP API request: " . $url);
$response = Http::sendHttpRequestBy('curl', $url, $timeout = 0, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $this->acceptInvalidSSLCertificate);
$output->write($response);
} catch (\Exception $e) {
$message = "Got invalid response from API request: {$url}. ";
if (isset($response) && empty($response)) {
$message .= "The response was empty. This usually means a server error. This solution to this error is generally to increase the value of 'memory_limit' in your php.ini file. Please check your Web server Error Log file for more details.";
} else {
$message .= "Response was '" . $e->getMessage() . "'";
}
$output->write($message);
Log::debug($e);
}
}
示例6: testSocketHttpsWorksEvenWithInvalidCertificate
/**
* We check that HTTPS is not supported with the "socket" method
*/
public function testSocketHttpsWorksEvenWithInvalidCertificate()
{
$result = Http::sendHttpRequestBy('socket', 'https://divezone.net', 10);
$this->assertNotEmpty($result);
}
示例7: checkPiwikServerWorking
/**
* Returns true if the Piwik server appears to be working.
*
* @param $piwikServerUrl
* @return bool
*/
public static function checkPiwikServerWorking($piwikServerUrl)
{
// Now testing if the webserver is running
try {
$fetched = Http::sendHttpRequestBy('curl', $piwikServerUrl, $timeout = 45, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = true);
} catch (Exception $e) {
$fetched = "ERROR fetching: " . $e->getMessage();
}
$expectedString = 'plugins/CoreHome/images/favicon.ico';
if (strpos($fetched, $expectedString) === false) {
throw new Exception("\nPiwik should be running at: " . $piwikServerUrl . " but this URL returned an unexpected response: '" . $fetched . "'\n\n");
}
}
示例8: executeNotAsyncHttp
private function executeNotAsyncHttp($url, Output $output)
{
$piwikUrl = $this->urlToPiwik ?: SettingsPiwik::getPiwikUrl();
if (empty($piwikUrl)) {
$piwikUrl = 'http://' . Url::getHost() . '/';
}
$url = $piwikUrl . $url;
if (Config::getInstance()->General['force_ssl'] == 1) {
$url = str_replace("http://", "https://", $url);
}
if ($this->runAsSuperUser) {
$tokenAuths = self::getSuperUserTokenAuths();
$tokenAuth = reset($tokenAuths);
if (strpos($url, '?') === false) {
$url .= '?';
} else {
$url .= '&';
}
$url .= 'token_auth=' . $tokenAuth;
}
try {
Log::debug("Execute HTTP API request: " . $url);
$response = Http::sendHttpRequestBy('curl', $url, $timeout = 0, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $this->acceptInvalidSSLCertificate);
$output->write($response);
} catch (\Exception $e) {
$message = "Got invalid response from API request: {$url}. ";
if (isset($response) && empty($response)) {
$message .= "The response was empty. This usually means a server error. This solution to this error is generally to increase the value of 'memory_limit' in your php.ini file. Please check your Web server Error Log file for more details.";
} else {
$message .= "Response was '" . $e->getMessage() . "'";
}
$output->write($message);
Log::debug($e);
}
}
示例9: request
/**
* Issues a request to $url
*/
private function request($url)
{
$url = $this->piwikUrl . $url . self::APPEND_TO_API_REQUEST;
if ($this->shouldStartProfiler) {
$url .= "&xhprof=2";
}
//$this->log($url);
try {
$response = Http::sendHttpRequestBy('curl', $url, $timeout = 300, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSSLCertificate = $this->acceptInvalidSSLCertificate);
} catch (Exception $e) {
return $this->logNetworkError($url, $e->getMessage());
}
if ($this->checkResponse($response, $url)) {
return $response;
}
return false;
}
示例10: download
/**
* Downloads data from the given URL via a POST request. If a destination path is given, the downloaded data
* will be stored in the given path and returned otherwise.
*
* Make sure to call {@link authenticate()} to download paid plugins.
*
* @param string $url An absolute URL to the marketplace including domain.
* @param null|string $destinationPath
* @param null|int $timeout Defaults to 60 seconds see {@link self::HTTP_REQUEST_METHOD}
* @return bool|string Returns the downloaded data or true if a destination path was given.
* @throws \Exception
*/
public function download($url, $destinationPath = null, $timeout = null)
{
$method = Http::getTransportMethod();
if (!isset($timeout)) {
$timeout = static::HTTP_REQUEST_TIMEOUT;
}
$post = null;
if ($this->accessToken) {
$post = array('access_token' => $this->accessToken);
}
$file = Http::ensureDestinationDirectoryExists($destinationPath);
$response = Http::sendHttpRequestBy($method, $url, $timeout, $userAgent = null, $destinationPath, $file, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'POST', $httpUsername = null, $httpPassword = null, $post);
return $response;
}