本文整理汇总了PHP中Guzzle\Http\ClientInterface::post方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::post方法的具体用法?PHP ClientInterface::post怎么用?PHP ClientInterface::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
/**
* {@inheritdoc}
*/
public function post($url, array $headers = array(), $content = '')
{
$headers['content-type'] = 'application/json';
$request = $this->client->post($url, $headers, $content);
$this->response = $request->send();
return $this->response->getBody(true);
}
示例2: postContent
/**
* {@inheritdoc}
*/
public function postContent($url, array $headers = array(), array $content = array(), array $files = array())
{
$request = $this->client->post($url, $headers, $content);
foreach ($files as $key => $file) {
$request->addPostFile($key, $file);
}
return $this->sendRequest($request);
}
示例3: track
public function track($trackingNumber)
{
try {
$response = $this->httpClient->post($this->url, array(), array('API' => 'TrackV2', 'XML' => $this->createTrackRequestXml($trackingNumber)))->send();
} catch (HttpException $e) {
throw Exception::createFromHttpException($e);
}
return $this->parseTrackResponse($response->getBody(true), $trackingNumber);
}
示例4: track
public function track($trackingNumber)
{
$body = $this->createAuthenticationXml() . $this->createTrackXml($trackingNumber);
try {
$response = $this->httpClient->post($this->url, array(), $body)->send();
} catch (HttpException $e) {
throw Exception::createFromHttpException($e);
}
return $this->parse($response->getBody(true));
}
示例5: call
public function call($wrappedClass, $method, array $params = array())
{
$request = $this->client->post(sprintf('/%s/%s', str_replace('\\', '/', $wrappedClass), $method), $params);
$auth = $this->getAuthConfig($this->auth);
if ($auth) {
$request->setAuth($auth['login'], $auth['pass'], $auth['type']);
}
$response = $request->send();
return $response->getBody();
}
示例6: post
/**
* {@inheritdoc}
*/
public function post($url, $content = '')
{
$request = $this->client->post($url, [], $content);
try {
$this->response = $request->send();
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}
return $this->response->getBody(true);
}
示例7: format
/**
* {@inheritDoc}
*/
public function format($string)
{
$request = $this->client->post('markdown', null, json_encode(array('text' => $string)));
try {
$response = $request->send();
} catch (BadResponseException $e) {
$response = $e->getResponse();
$json = $response->json();
throw new RuntimeException(sprintf('Request to Github failed: %s [%d]', $json['message'], $response->getStatusCode()));
}
return $response->getBody(true);
}
示例8: buildRequestObject
/**
* @param array $postData
* @return \Guzzle\Http\Message\EntityEnclosingRequestInterface|\Guzzle\Http\Message\RequestInterface
* @throws Exceptions\BadServiceException
* @throws Exceptions\AppNexusAPIException
*/
private function buildRequestObject(array $postData = array())
{
$where = $this->where;
if (isset($where['since'])) {
if (!$this->getServiceObject($this->getService())->supportsSince()) {
throw new BadServiceException(sprintf("[%s] does not support `since()`", $this->getService()));
}
switch ($this->getService()) {
case self::SERVICE_LANGUAGE:
$key = 'min_last_activity';
break;
default:
$key = 'min_last_modified';
break;
}
$where[$key] = $where['since'];
unset($where['since']);
}
$uri = sprintf("/%s?%s", $this->getService(), http_build_query($where));
switch ($this->getServiceObject($this->getService())->getRequestVerb()) {
case 'get':
return $this->client->get($uri, array('Authorization' => $this->token));
break;
case 'post':
return $this->client->post($uri, array('Authorization' => $this->token), json_encode($postData));
break;
default:
throw new AppNexusAPIException(sprintf("Unknown verb [%s]", $this->getServiceObject($this->getService())->getRequestVerb()));
}
}
示例9: postJson
/**
* {@inheritDoc}
*/
public function postJson($path, $postBody, array $parameters = array(), array $headers = array())
{
$parameters = $this->buildQueryParameters($parameters);
$request = $this->client->post($path, $headers, null, $parameters);
$request->setBody($postBody, 'application/json');
return $this->request($request);
}
示例10: updateTranslation
/**
* {@inheritdoc}
*/
public function updateTranslation($masterfile, $lang, $filePath)
{
$url = $this->getApiUrl('translation', array('master-file-name' => $masterfile, 'language-tag' => $lang));
$response = $this->httpClient->post($url)->addPostFile('file', $filePath)->send();
if (!$response->isSuccessful()) {
throw new RuntimeException('Something went wrong dialing with the api server: ' . $response->getBody());
}
return $response->getBody(true);
}
示例11: enableOauthAuthentication
public function enableOauthAuthentication($key, $secret, $accessToken = null, $code = null)
{
$this->key = $key;
$this->secret = $secret;
$this->accessToken = $accessToken;
$this->code = $code;
if (!$accessToken && !$code) {
throw new InvalidArgumentException(sprintf("No OAuth code or access token given, please visit %s to generate a new code", "https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id={$key}"));
} elseif (!$accessToken && $code) {
$request = $this->client->post('oauth2/token', array(), array('code' => $this->code, 'grant_type' => 'authorization_code', 'client_id' => $this->key, 'client_secret' => $this->secret));
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$this->handleBadResponseExceptions($e);
}
$token = $response->json();
$this->accessToken = $token['access_token'];
}
$this->client->setDefaultOption('request.options/headers/Authorization', 'Bearer ' . $this->accessToken);
}
示例12: send
/**
* {@inheritdoc}
*/
public function send(MessageInterface $message)
{
// Validate we have everything we need
foreach (array('token', 'room', 'from') as $variable) {
if (empty($this->{$variable})) {
throw new InvalidArgumentException("Invalid `{$variable}`");
}
}
// Build up the data we are sending to Hipchat
$data = array('room_id' => $this->getRoom(), 'from' => $this->getFrom(), 'message' => $message->getMessage(), 'message_format' => $message->getMessageFormat(), 'notify' => $message->getNotification(), 'color' => $message->getBackgroundColor(), 'format' => 'json');
$data = http_build_query($data, '', '&');
return $this->http->post($this->getUri(), $this->getHeaders(), $data)->send();
}
示例13: refreshToken
private function refreshToken()
{
$request = $this->client->post('https://accounts.google.com/o/oauth2/token', array(), array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'refresh_token' => $this->refreshToken, 'grant_type' => 'refresh_token'));
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$this->handleBadResponseExceptions($e);
}
$token = $response->json();
if (!isset($token['access_token'])) {
throw new RuntimeException('Invalid token response received from Google Drive');
}
$this->enableOAuth2Authentication($this->clientId, $this->clientSecret, $token['access_token'], $this->refreshToken);
}
示例14: getToken
/**
* @param AccessToken $token
* @return AcccessToken
*/
public function getToken(AccessToken $token = null)
{
if ($token && $token->getRefreshToken()) {
$this->body['grant_type'] = 'refresh_token';
$this->body['refresh_token'] = $token->getRefreshToken();
} else {
$this->buildBody();
}
$request = $this->client->post($this->tokenRequestPath, $this->headers, $this->body);
$response = $request->send();
$data = $response->json();
$refreshToken = isset($data['data']['refresh_token']) ?: '';
return new AccessToken($data['data']['access_token'], $refreshToken, $data['data']['expires_in']);
}
示例15: post
/**
* {@inheritdoc}
*/
public function post($url, $content = '')
{
$request = $this->client->post($url);
if (is_array($content)) {
$request->setBody(json_encode($content), 'application/json');
} else {
$request->setBody($content);
}
try {
$this->response = $request->send();
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}
return $this->response->getBody(true);
}