本文整理汇总了PHP中Guzzle\Service\Client::createRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::createRequest方法的具体用法?PHP Client::createRequest怎么用?PHP Client::createRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Client
的用法示例。
在下文中一共展示了Client::createRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postJSON
private function postJSON($url, $headers, $payload)
{
$client = new Client();
$request = $client->createRequest('POST', $url, ["Content-Type" => "application/json;charset=UTF-8", "Accept" => "application/json"] + $headers, $payload);
$response = $request->send();
$json = $response->getBody(true);
return json_decode($json);
}
示例2: createRequest
/**
* {@inheritdoc}
* Also includes the `api_id`, `user`, and `password` in the request if
* `session_id` has not been provided in the request.
*/
public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
{
$request = parent::createRequest($method, $uri, $headers, $body, $options);
if (!$request->getPostField("session_id")) {
$config = $this->getConfig();
$request->addPostFields($config->getAll(array('api_id', 'user', 'password')));
}
return $request;
}
示例3: createRequest
/**
* {@inheritDoc}
*/
public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
{
$request = parent::createRequest($method, $uri, $headers, $body, $options);
$config = $this->getConfig();
// Add curl authentication to the request when username and password is set.
if ($config->hasKey('username') && $config->hasKey('password')) {
$authPlugin = new CurlAuthPlugin($config->get('username'), $config->get('password'));
$this->addSubscriber($authPlugin);
} elseif ($config->hasKey('client_id') && $config->hasKey('client_secret')) {
$request->getQuery()->set('client_id', $config->get('client_id'))->set('client_secret', $config->get('client_secret'));
}
return $request;
}
示例4: getGosling
/**
* Function doing an sql injection on GET with Guzzle
* @param SqlTarget $target
*/
public function getGosling(TargetInterface $target)
{
//defining $url and $params from $target
//setting success to false by default
$url = $target->getUrl();
$repo = $this->_em->getRepository('AppBundle:SqlError');
$sql_error = $repo->getSqlError();
$params = $this->changeParamsToHackParams($target, $sql_error);
$req = $this->_guzzle->createRequest('GET', $url, $params);
$result = $this->goslingResponse($req, $url);
$used_sql_error = $sql_error->getValue();
$success = $result["Success"];
$this->report($success, "for url " . $url . "and slq injection : " . $used_sql_error);
}
示例5: request
/**
* Dispatch API request
*
* @param string $method HTTP method
* @param string $path Target path relative to base_url option value
* @param object $paramData Request data
*
* @return mixed Response object
*/
public function request($method, $path, $paramData)
{
$req = $this->client->createRequest($method, $path, array());
$query = $req->getQuery();
foreach ($paramData->queryParams() as $k => $v) {
if ($v === null) {
continue;
}
$query->add($k, is_bool($v) ? $v ? 'true' : 'false' : $v);
}
if ($method !== 'get' && $method !== 'delete') {
$body = $paramData->requestBody();
$json = empty($body) ? '{}' : json_encode($body);
$req->setBody($json, 'application/json');
}
try {
$res = $req->send();
return $res->json();
} catch (\Guzzle\Common\Exception\RuntimeException $e) {
throw ApiConnectionException::inRequest($e);
}
}
示例6: request
/**
* Dispatch API request
*
* @param string $operation Target action
* @param object $paramData Request data
*
*/
public function request($method, $path, $paramData)
{
if ($method == 'get' && count($paramData) > 0) {
$path = $path . '?';
foreach ($paramData as $k => $v) {
$path .= $k . '=' . $v;
}
$paramData = array();
}
$this->setSignature($path, $paramData);
$req = $this->client->createRequest($method, $path, array());
if ($method == 'post' || $method == 'delete') {
foreach ($paramData as $k => $v) {
$req->setPostField($k, $v);
}
}
try {
$res = $req->send();
return $res->json();
} catch (\Guzzle\Common\Exception\RuntimeException $e) {
echo $e->getResponse()->getBody();
}
}
示例7: createRequest
/**
* Ensures that the duplicate query string aggregator is used so that
* query string values are sent over the wire as foo=bar&foo=baz.
* {@inheritdoc}
*/
public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
{
$request = parent::createRequest($method, $uri, $headers, $body, $options);
$request->getQuery()->setAggregator($this->aggregator);
return $request;
}
示例8: createRequest
/**
* Create and return a new RequestInterface configured for the client.
*
* Used internally by the library. Do not use directly.
*
* @param string $method HTTP method. Default to GET.
* @param string|array $uri Resource URI
* @param array|Collection $headers HTTP headers
* @param string|resource|array|EntityBodyInterface $body Entity body of request (POST/PUT) or response (GET)
* @param array $options Array of options to apply to the request
*
* @return RequestInterface
*/
public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
{
if (is_array($body)) {
$body['pio_appkey'] = $this->getConfig()->get("appkey");
} else {
$body = array('pio_appkey' => $this->getConfig()->get("appkey"));
}
// Remove Guzzle internals to prevent them from going to the API
unset($body[AbstractCommand::HEADERS_OPTION]);
unset($body[AbstractCommand::ON_COMPLETE]);
unset($body[AbstractCommand::DISABLE_VALIDATION]);
unset($body[AbstractCommand::RESPONSE_PROCESSING]);
unset($body[AbstractCommand::RESPONSE_BODY]);
unset($body[AbstractCommand::HIDDEN_PARAMS]);
if ($method == RequestInterface::GET || $method == RequestInterface::DELETE) {
$request = parent::createRequest($method, $uri, $headers, null, $options);
$request->getQuery()->replace($body);
} else {
$request = parent::createRequest($method, $uri, $headers, $body, $options);
}
$request->setPath($request->getPath() . ".json");
return $request;
}
示例9: createMpiRequest
/**
* Creates mpi request as innovate api need it.
*
* @param string $method
* @param string $uri
* @param array $headers
* @param string|resource|array|EntityBodyInterface $body
* @return \Guzzle\Http\Message\RequestInterface
*/
public function createMpiRequest($method = 'GET', $uri = null, $headers = null, $body = null)
{
$request = parent::createRequest($method, $uri, $headers, $body);
if (!$body) {
$request->createMpiBody($this->getStoreId(), $this->getKey(), $this->getTransaction(), $this->getCard(), $this->getBillingInformation(), $this->getBrowser());
}
return $request;
}
示例10: getChunks
/**
* @param string $bodyString
* @see https://developers.google.com/safe-browsing/developers_guide_v2#HTTPRequestForData
* @return array
*/
public function getChunks($bodyString = '')
{
$resource = 'downloads';
$client = new Client($this->getServiceUrl($resource));
$request = $client->createRequest('POST', null, null, $bodyString);
$response = $this->sendRequest($request);
return array('code' => $response->getStatusCode(), 'data' => $response->getBody(true));
}
示例11: checkPublishing
/**
* @param string $path
* @return string|bool
*/
public function checkPublishing($path = '')
{
$client = new Client($this->getServiceUrl());
$body = '<propfind xmlns="DAV:"><prop><public_url xmlns="urn:yandex:disk:meta"/></prop></propfind>';
$request = $client->createRequest('PROPFIND', $path, array('Content-Length' => strlen($body), 'Depth' => '0'), $body);
$result = $this->sendRequest($request)->xml()->children('DAV:');
$propArray = (array) $result->response->propstat->prop->children();
return empty($propArray['public_url']) ? (bool) false : (string) $propArray['public_url'];
}
示例12: createRequest
/**
*
* @see \Guzzle\Http\Client::createRequest()
*/
public function createRequest($method = RequestInterface::POST, $uri = null, $headers = null, $body = null, array $options = array())
{
$request = parent::createRequest($method, $uri, $headers, $body, $options);
return $request;
}
示例13: updateDelivery
/**
* Update changed delivery parameters
*
* @param int $orderId
* @param Models\Delivery $delivery
* @return Models\Order
*
* Example:
* PUT /v2/campaigns/10003/order/12345/delivery.json HTTP/1.1
*
* @link http://api.yandex.ru/market/partner/doc/dg/reference/put-campaigns-id-orders-id-delivery.xml
*/
public function updateDelivery($orderId, Models\Delivery $delivery)
{
$resource = 'campaigns/' . $this->campaignId . '/orders/' . $orderId . '/delivery.json';
$data = json_encode($delivery->toArray());
$client = new Client($this->getServiceUrl($resource));
$request = $client->createRequest('PUT', null, null, $data);
$request->setHeader('Content-type', 'application/json');
$response = $this->sendRequest($request)->json();
$updateOrderDeliveryResponse = new Models\UpdateOrderDeliveryResponse($response);
return $updateOrderDeliveryResponse->getOrder();
}
示例14: createRequest
/**
* {@inheritdoc}
*/
public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null)
{
$request = parent::createRequest($method, $uri, $headers, $body);
$request->setHeader('Content-Type', 'text/xml');
return $request;
}
示例15: createRequest
/**
* {@inheritdoc}
*
* Prepends the {+base_path} expressions to the URI
*/
public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
{
$uri = '{+base_path}/' . ltrim($uri, '/');
return parent::createRequest($method, $uri, $headers, $body, $options);
}