本文整理汇总了PHP中Zend\Http\Client::setRawBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setRawBody方法的具体用法?PHP Client::setRawBody怎么用?PHP Client::setRawBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setRawBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PlanJSONManager
function PlanJSONManager($action, $url, $requestjson, $uid)
{
$request = new Request();
$request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
//$url="";
try {
$request->setUri($url);
$request->setMethod($action);
$client = new Client();
if ($action == 'PUT' || $action == 'POST') {
$client->setUri($url);
$client->setMethod($action);
$client->setRawBody($requestjson);
$client->setEncType('application/json');
$response = $client->send();
return $response;
} else {
$response = $client->dispatch($request);
//var_dump(json_decode($response->getBody(),true));
return $response;
}
} catch (\Exception $e) {
$e->getTrace();
}
return null;
}
示例2: send
/**
* @param MessageInterface|Message $message
* @return mixed|void
* @throws RuntimeException
*/
public function send(MessageInterface $message)
{
$config = $this->getSenderOptions();
$serviceURL = "http://letsads.com/api";
$body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
$auth = $body->addChild('auth');
$auth->addChild('login', $config->getUsername());
$auth->addChild('password', $config->getPassword());
$messageXML = $body->addChild('message');
$messageXML->addChild('from', $config->getSender());
$messageXML->addChild('text', $message->getMessage());
$messageXML->addChild('recipient', $message->getRecipient());
$client = new Client();
$client->setMethod(Request::METHOD_POST);
$client->setUri($serviceURL);
$client->setRawBody($body->asXML());
$client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
try {
$response = $client->send();
} catch (Client\Exception\RuntimeException $e) {
throw new RuntimeException("Failed to send sms", null, $e);
}
try {
$responseXML = new \SimpleXMLElement($response->getBody());
} catch (\Exception $e) {
throw new RuntimeException("Cannot parse response", null, $e);
}
if ($responseXML->name === 'error') {
throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
}
}
示例3: doPostRequest
public function doPostRequest()
{
$url = 'http://www.mvg-live.de/MvgLive/mvglive/rpc/newstickerService';
$client = new Client();
$client->setUri($url);
$client->setMethod(\Zend\Http\Request::METHOD_POST);
$headers = array('Origin' => 'http://www.mvg-live.de', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,da;q=0.2', 'X-GWT-Module-Base' => 'http://www.mvg-live.de/MvgLive/mvglive/', 'Connection' => 'keep-alive', 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36', 'Content-Type' => 'text/x-gwt-rpc; charset=UTF-8', 'Accept' => '*/*', 'X-GWT-Permutation' => '1DD521F1FA9966B50432692AB421CD55', 'Referer' => 'http://www.mvg-live.de/MvgLive/MvgLive.jsp', 'DNT' => '1');
$client->setHeaders($headers);
$client->setRawBody('7|0|4|http://www.mvg-live.de/MvgLive/mvglive/|7690A2A77A0295D3EC713772A06B8898|de.swm.mvglive.gwt.client.newsticker.GuiNewstickerService|getNewsticker|1|2|3|4|0|');
$response = $client->send();
return $response->getBody();
}
示例4: insert
public function insert(Nfse $nfse, $reference)
{
$url = $this->_server . "/nfe2/autorizar/?token={$this->_token}&ref={$reference}";
$client = new Client($url);
$client->setMethod('POST');
$dumper = new Dumper();
$yaml = $dumper->dump($nfse->getNfse());
$client->setRawBody($yaml);
$response = $client->send();
$this->_responseBody = $response->getBody();
return $response->isSuccess();
}
示例5: executePost
public static function executePost($uri, $value)
{
$client = new Client();
$client->setUri($uri);
$client->setMethod(Request::METHOD_POST);
$client->setRawBody($value);
$client->setHeaders(array('Content-Type: text/plain'));
$response = $client->send();
if ($response->getStatusCode() >= 300) {
throw new \Exception(sprintf('Request Response: Status Code %d, Url: %s', $response->getStatusCode(), $uri));
}
return $response->getBody();
}
示例6: testStreamRequest
public function testStreamRequest()
{
if (!$this->client->getAdapter() instanceof Adapter\StreamInterface) {
$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');
}
示例7: doWrite
/**
* Write a message to the log.
*
* @param array $event event data
*
* @return void
* @throws \Zend\Log\Exception\RuntimeException
*/
protected function doWrite(array $event)
{
// Apply verbosity filter:
if (is_array($event['message'])) {
$event['message'] = $event['message'][$this->verbosity];
}
// Create request
$this->client->setUri($this->url);
$this->client->setMethod('POST');
$this->client->setEncType($this->contentType);
$this->client->setRawBody($this->getBody($this->applyVerbosity($event)));
// Send
$response = $this->client->send();
}
示例8: callRaynetcrmRestApi
/**
* Requests RAYNET Cloud CRM REST API. Check https://s3-eu-west-1.amazonaws.com/static-raynet/webroot/api-doc.html for any further details.
*
* @param $serviceName string URL service name
* @param $method string Http method
* @param $request array request
* @return \Zend\Http\Response response
*/
private function callRaynetcrmRestApi($serviceName, $method, $request)
{
$client = new Client('', array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
$client->setMethod($method);
$client->setUri($this->buildUrl($serviceName));
$client->setHeaders(array('X-Instance-Name' => $this->fInstanceName, 'Content-Type' => 'application/json; charset=UTF-8'));
$client->setAuth($this->fUserName, $this->fApiKey);
if ($method === self::HTTP_METHOD_GET) {
$client->setParameterGet($request);
} else {
$client->setRawBody(Json::encode($request));
}
return $client->send();
}
示例9: 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->getLastRawRequest();
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]);
}
示例10: httpRequest
/**
* Perform an HTTP request.
*
* @param string $baseUrl Base URL for request
* @param string $method HTTP method for request
* @param string $queryString Query string to append to URL
* @param array $headers HTTP headers to send
*
* @throws SerialsSolutions_Summon_Exception
* @return string HTTP response body
*/
protected function httpRequest($baseUrl, $method, $queryString, $headers)
{
$this->debugPrint("{$method}: {$baseUrl}?{$queryString}");
$this->client->resetParameters();
if ($method == 'GET') {
$baseUrl .= '?' . $queryString;
} elseif ($method == 'POST') {
$this->client->setRawBody($queryString, 'application/x-www-form-urlencoded');
}
$this->client->setHeaders($headers);
// Send Request
$this->client->setUri($baseUrl);
$result = $this->client->setMethod($method)->send();
if (!$result->isSuccess()) {
throw new SerialsSolutions_Summon_Exception($result->getBody());
}
return $result->getBody();
}
示例11: httpRequest
/**
* Perform an HTTP request.
*
* @param string $baseUrl Base URL for request
* @param string $method HTTP method for request (GET,POST, etc.)
* @param string $queryString Query string to append to URL
* @param array $headers HTTP headers to send
* @param string $messageBody Message body to for HTTP Request
* @param string $messageFormat Format of request $messageBody and respones
*
* @throws EbscoEdsApiException
* @return string HTTP response body
*/
protected function httpRequest($baseUrl, $method, $queryString, $headers, $messageBody = null, $messageFormat = "application/json; charset=utf-8")
{
$this->debugPrint("{$method}: {$baseUrl}?{$queryString}");
$this->client->resetParameters();
$this->client->setHeaders($headers);
$this->client->setMethod($method);
if ($method == 'GET' && !empty($queryString)) {
$baseUrl .= '?' . $queryString;
} elseif ($method == 'POST' && isset($messageBody)) {
$this->client->setRawBody($messageBody);
}
$this->client->setUri($baseUrl);
$this->client->setEncType($messageFormat);
$result = $this->client->send();
if (!$result->isSuccess()) {
throw new \EbscoEdsApiException(json_decode($result->getBody(), true));
}
return $result->getBody();
}
示例12: basicOauthPostConnect
/**
* @param $endpoint
* @param $token
* @param $postArray
* @return array
* @throws \Exception
*/
public function basicOauthPostConnect($endpoint, $token, $postArray)
{
$client = new Client($endpoint, ['maxredirects' => 0, 'timeout' => 60]);
$client->setMethod('POST');
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
//to deal with ssl errors
$client->setHeaders(['content-type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $token]);
// $data = array(
// $postArray
// );
$json = json_encode($postArray);
$client->setRawBody($json, 'application/json');
try {
$response = $client->send();
} catch (\Exception $e) {
throw new \Exception($e);
}
$responseObject = json_decode($response->getBody());
if (is_null($responseObject)) {
return false;
}
$hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty();
return $hydrator->extract($responseObject);
}
示例13: sendMessage
public function sendMessage($postdata)
{
$defaults = array('publisher' => $this->config['publisher'], 'provider' => '', 'message' => '', 'message_plain' => '', 'lang' => '', 'property_reference' => '', 'salutation_code' => '', 'firstname' => '', 'lastname' => '', 'legal_name' => '', 'street' => '', 'postal_code' => '', 'locality' => '', 'phone' => '', 'mobile' => '', 'fax' => '', 'email' => '');
$postdata = array_merge($defaults, $postdata);
$postdata['publisher'] = $this->config['publisher'];
if ($postdata['message'] && !$postdata['message_plain']) {
$postdata['message'] = $this->sanitizeHtml($postdata['message']);
$postdata['message_plain'] = strip_tags($postdata['message']);
}
if (!$postdata['message'] && $postdata['message_plain']) {
$postdata['message_plain'] = strip_tags($postdata['message_plain']);
$postdata['message'] = $this->sanitizeHtml($postdata['message_plain']);
}
if ($postdata['message'] && $postdata['message_plain']) {
$postdata['message_plain'] = strip_tags($postdata['message_plain']);
$postdata['message'] = $this->sanitizeHtml($postdata['message_plain']);
}
$config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FRESH_CONNECT => true));
$query = array();
$uri = $this->config['url'] . '/msg?' . http_build_query($query);
$client = new HttpClient($uri, $config);
$client->setHeaders(array('Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json'));
$client->setMethod('POST');
$client->setRawBody(Json::encode($postdata));
$client->setEncType(HttpClient::ENC_FORMDATA);
$client->setAuth($this->config['username'], $this->config['password'], \Zend\Http\Client::AUTH_BASIC);
$response = $client->send();
return $response->getContent();
}
示例14: index
/**
* Store or update an entity in the search index
*
* @param array $data
* @throws Exception\RuntimeException
* @throws Exception\IndexException
* @return boolean true if successfull
*/
protected function index(array $data)
{
$adapter = new Http\Client\Adapter\Curl();
$adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
$client = new Http\Client();
$client->setAdapter($adapter);
$client->setMethod('POST');
$client->setUri($this->getDocumentEndpoint());
$client->setRawBody(Json::encode($data));
$client->setHeaders(array('Content-Type' => 'application/json'));
$response = $client->send();
if (!$response->isSuccess()) {
if ($this->throwExceptions) {
throw new Exception\IndexException("Bad response received from CloudSearch.\n" . $response->toString());
}
return false;
}
$results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
$count = $results['adds'] + $results['deletes'];
return $count != count($data) ? 0 : $count;
}
示例15: performHttpRequest
/**
* Performs a HTTP request using the specified method
*
* @param string $method The HTTP method for the request - 'GET', 'POST',
* 'PUT', 'DELETE'
* @param string $uri The URL to which this request is being performed
* @param array $headers An associative array of HTTP headers
* for this request
* @param string $body The body of the HTTP request
* @param string $contentType The value for the content type
* of the request body
* @param int $remainingRedirects Number of redirects to follow if request
* s results in one
* @return \Zend\Http\Response The response object
*/
public function performHttpRequest($method, $uri, $headers = null, $body = null, $contentType = null, $remainingRedirects = null)
{
if ($remainingRedirects === null) {
$remainingRedirects = self::getMaxRedirects();
}
if ($headers === null) {
$headers = array();
}
// Append a GData version header if protocol v2 or higher is in use.
// (Protocol v1 does not use this header.)
$major = $this->getMajorProtocolVersion();
$minor = $this->getMinorProtocolVersion();
if ($major >= 2) {
$headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : '');
}
// check the overridden method
if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') {
throw new App\InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of ZendGData\\App\\Entry');
}
if ($uri === null) {
throw new App\InvalidArgumentException('You must specify an URI to which to post.');
}
if ($contentType != null) {
$headers['Content-Type'] = $contentType;
}
if (self::getGzipEnabled()) {
// some services require the word 'gzip' to be in the user-agent
// header in addition to the accept-encoding header
if (strpos($this->_httpClient->getHeaders()->get('User-Agent'), 'gzip') === false) {
$headers['User-Agent'] = $this->_httpClient->getHeaders()->get('User-Agent') . ' (gzip)';
}
$headers['Accept-encoding'] = 'gzip, deflate';
} else {
$headers['Accept-encoding'] = 'identity';
}
// Make sure the HTTP client object is 'clean' before making a request
// In addition to standard headers to reset via resetParameters(),
// also reset the Slug and If-Match headers
$this->_httpClient->resetParameters();
$this->_httpClient->setHeaders(array('Slug' => 'If-Match'));
// Set the params for the new request to be performed
$this->_httpClient->setHeaders($headers);
$uriObj = Uri\UriFactory::factory($uri);
preg_match("/^(.*?)(\\?.*)?\$/", $uri, $matches);
$this->_httpClient->setUri($matches[1]);
$queryArray = $uriObj->getQueryAsArray();
$this->_httpClient->setParameterGet($queryArray);
$this->_httpClient->setOptions(array('maxredirects' => 0));
// Set the proper adapter if we are handling a streaming upload
$usingMimeStream = false;
$oldHttpAdapter = null;
if ($body instanceof \ZendGData\MediaMimeStream) {
$usingMimeStream = true;
$this->_httpClient->setRawDataStream($body, $contentType);
$oldHttpAdapter = $this->_httpClient->getAdapter();
if ($oldHttpAdapter instanceof \Zend\Http\Client\Adapter\Proxy) {
$newAdapter = new HttpAdapterStreamingProxy();
} else {
$newAdapter = new HttpAdapterStreamingSocket();
}
$this->_httpClient->setAdapter($newAdapter);
} else {
$this->_httpClient->setRawBody($body);
}
try {
$this->_httpClient->setMethod($method);
$response = $this->_httpClient->send();
// reset adapter
if ($usingMimeStream) {
$this->_httpClient->setAdapter($oldHttpAdapter);
}
} catch (\Zend\Http\Client\Exception\ExceptionInterface $e) {
// reset adapter
if ($usingMimeStream) {
$this->_httpClient->setAdapter($oldHttpAdapter);
}
throw new App\HttpException($e->getMessage(), $e);
}
if ($response->isRedirect() && $response->getStatusCode() != '304') {
if ($remainingRedirects > 0) {
$newUrl = $response->getHeaders()->get('Location')->getFieldValue();
$response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects);
} else {
throw new App\HttpException('Number of redirects exceeds maximum', null, $response);
}
//.........这里部分代码省略.........