本文整理汇总了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;
}