本文整理汇总了PHP中Zend_Http_Client::setRawBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::setRawBody方法的具体用法?PHP Zend_Http_Client::setRawBody怎么用?PHP Zend_Http_Client::setRawBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::setRawBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testStreamRequest
public function testStreamRequest()
{
if (!$this->client->getAdapter() instanceof Adapter\Stream) {
$this->markTestSkipped('Current adapter does not support streaming');
return;
}
$data = fopen(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'staticFile.jpg', "r");
$this->client->setRawBody($data);
$this->client->setEncType('image/jpeg');
$this->client->setMethod('PUT');
$res = $this->client->send();
$expected = $this->_getTestFileContents('staticFile.jpg');
$this->assertEquals($expected, $res->getBody(), 'Response body does not contain the expected data');
}
示例2: testMultibyteRawPostDataZF2098
/**
* Test that we properly calculate the content-length of multibyte-encoded
* request body
*
* This may file in case that mbstring overloads the substr and strlen
* functions, and the mbstring internal encoding is a multibyte encoding.
*
* @link http://framework.zend.com/issues/browse/ZF-2098
*/
public function testMultibyteRawPostDataZF2098()
{
$this->_client->setAdapter('Zend\\Http\\Client\\Adapter\\Test');
$this->_client->setUri('http://example.com');
$bodyFile = __DIR__ . '/_files/ZF2098-multibytepostdata.txt';
$this->_client->setRawBody(file_get_contents($bodyFile));
$this->_client->setEncType('text/plain');
$this->_client->setMethod('POST');
$this->_client->send();
$request = $this->_client->getLastRequest();
if (!preg_match('/^content-length:\\s+(\\d+)/mi', $request, $match)) {
$this->fail("Unable to find content-length header in request");
}
$this->assertEquals(filesize($bodyFile), (int) $match[1]);
}
示例3: _performRequest
/**
* Perform request using Zend_Http_Client channel
*
* @param string $path Path
* @param string $queryString Query string
* @param string $httpVerb HTTP verb the request will use
* @param array $headers x-ms headers to add
* @param boolean $forTableStorage Is the request for table storage?
* @param mixed $rawData Optional RAW HTTP data to be sent over the wire
* @param string $resourceType Resource type
* @param string $requiredPermission Required permission
* @return Zend_Http_Response
*/
protected function _performRequest($path = '/', $queryString = '', $httpVerb = Zend\Http\Client::GET, $headers = array(), $forTableStorage = false, $rawData = null, $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN, $requiredPermission = Zend_Service_WindowsAzure_Credentials_AbstractCredentials::PERMISSION_READ)
{
// Clean path
if (strpos($path, '/') !== 0) {
$path = '/' . $path;
}
// Clean headers
if ($headers === null) {
$headers = array();
}
// Ensure cUrl will also work correctly:
// - disable Content-Type if required
// - disable Expect: 100 Continue
if (!isset($headers["Content-Type"])) {
$headers["Content-Type"] = '';
}
$headers["Expect"] = '';
// Add version header
$headers['x-ms-version'] = $this->_apiVersion;
// URL encoding
$path = self::urlencode($path);
$queryString = self::urlencode($queryString);
// Generate URL and sign request
$requestUrl = $this->_credentials->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission);
$requestHeaders = $this->_credentials->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType, $requiredPermission);
// Prepare request
$this->_httpClientChannel->resetParameters(true);
$this->_httpClientChannel->setUri($requestUrl);
$this->_httpClientChannel->setHeaders($requestHeaders);
$this->_httpClientChannel->setRawBody($rawData);
// Execute request
$response = $this->_retryPolicy->execute(array($this->_httpClientChannel, 'request'), array($httpVerb));
return $response;
}