本文整理匯總了PHP中Zend\Http\Client::setStream方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::setStream方法的具體用法?PHP Client::setStream怎麽用?PHP Client::setStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testStreamResponseNamed
public function testStreamResponseNamed()
{
if (!($this->client->getAdapter() instanceof Adapter\StreamInterface)) {
$this->markTestSkipped('Current adapter does not support streaming');
return;
}
$this->client->setUri($this->baseuri . 'staticFile.jpg');
$outfile = tempnam(sys_get_temp_dir(), "outstream");
$this->client->setStream($outfile);
$response = $this->client->send();
$this->assertTrue($response instanceof Response\Stream, 'Request did not return stream response!');
$this->assertTrue(is_resource($response->getStream()), 'Request does not contain stream!');
$this->assertEquals($outfile, $response->getStreamName());
$stream_read = stream_get_contents($response->getStream());
$file_read = file_get_contents($outfile);
$expected = $this->_getTestFileContents('staticFile.jpg');
$this->assertEquals($expected, $stream_read, 'Downloaded stream does not seem to match!');
$this->assertEquals($expected, $file_read, 'Downloaded file does not seem to match!');
}
示例2: downloadFromJotForm
/**
*
* @param string $jotFormUrl
* @throws UnableToRetrieveJotFormFile
* @return $localFilePath
*/
public function downloadFromJotForm($jotFormUrl, $password)
{
$client = new Client();
$client->setUri($jotFormUrl);
$client->setOptions(array('maxredirects' => 2, 'timeout' => 30));
// Set Certification Path when https is used - does not work (yet)
if (strpos($jotFormUrl, 'https:') === 0) {
$client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE)));
}
// will use temp file
$client->setStream();
// Password, if set
if (!empty($password)) {
$client->setMethod(Request::METHOD_POST);
$client->setParameterPost(array('passKey' => $password));
}
$response = $client->send();
if ($response->getStatusCode() != 200) {
throw new UnableToRetrieveJotFormFile('Wront StatusCode: ' . $response->getStatusCode() . ' (StatusCode=200 expected)');
}
// Copy StreamInput
$tmpName = tempnam('/tmp', 'jotFormReport_');
copy($response->getStreamName(), $tmpName);
// Add to delete late
$this->downloads[] = $tmpName;
return $tmpName;
}
示例3: prepareHttpRequest
/**
* Prepare req
*
* @param Request $request
* @return Client
* @author Paolo Agostinetto <paul.ago@gmail.com>
*/
protected function prepareHttpRequest(Request $request)
{
$client = new Client("https://api.thumbalizr.com/", array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE)));
$client->setStream();
// Use temp file
$client->setParameterGet(array("api_key" => $this->apiKey, "quality" => $request->getQuality(), "width" => $request->getWidth(), "encoding" => $request->getEncoding(), "delay" => $request->getDelay(), "mode" => $request->getMode(), "bwidth" => $request->getBrowserWidth(), "bheight" => $request->getBrowserHeight(), "url" => $request->getUrl() . "&rnd=" . rand(100000, 999999999), "generate" => 0));
return $client;
}