本文整理汇总了PHP中GuzzleHttp\Client::options方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::options方法的具体用法?PHP Client::options怎么用?PHP Client::options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::options方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStatusCodeForUrl
/**
* Get HTTP status code for URL
* @param string $url The remote URL
* @return int The HTTP status code
*/
protected function getStatusCodeForUrl($url)
{
$httpResponse = $this->httpClient->options($url);
return $httpResponse->getStatusCode();
}
示例2: options
/**
* Sends a options request
* @param string $uri
* @param array $options Array such as
* 'body' => [
* 'field' => 'abc',
* 'other_field' => '123',
* 'file_name' => fopen('/path/to/file', 'r'),
* ],
* 'headers' => [
* 'foo' => 'bar',
* ],
* 'cookies' => ['
* 'foo' => 'bar',
* ],
* 'allow_redirects' => [
* 'max' => 10, // allow at most 10 redirects.
* 'strict' => true, // use "strict" RFC compliant redirects.
* 'referer' => true, // add a Referer header
* 'protocols' => ['https'] // only allow https URLs
* ],
* 'save_to' => '/path/to/file', // save to a file or a stream
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
* @return Response
* @throws \Exception If the request could not get completed
*/
public function options($uri, array $options = [])
{
$response = $this->client->options($uri, $options);
return new Response($response);
}
示例3: Client
<?php
/**
* Created by PhpStorm.
* User: raynald
* Date: 4/16/15
* Time: 10:00 AM
*/
// URL scanner app
// 1. Use Composer autoloader
require 'vendor/autoload.php';
use League\Csv\Reader;
use GuzzleHttp\Client;
// 2. Instantiate Guzzle HTTP client
$client = new Client();
// 3. Open and iterate CSV
// $csv = new \League\Csv\Reader($argv[1]);
$csv = Reader::createFromPath($argv[1]);
foreach ($csv as $url) {
try {
// 4. Send HTTP OPTIONS request
$httpResponse = $client->options($url[0]);
// 5. Inspect HTTP response status code
if ($httpResponse->getStatusCode() >= 400) {
throw new \Exception();
}
} catch (\Exception $e) {
// 6. Print bad URL to standard out
echo $url[0] . PHP_EOL;
}
}