本文整理汇总了PHP中GuzzleHttp\Client::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::post方法的具体用法?PHP Client::post怎么用?PHP Client::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$email = $request->email;
$password = $request->password;
$client = new Client();
$res = $client->post('https://api.pragyan.org/user/eventauth', array('body' => array('user_email' => $email, 'event_id' => '39', 'user_pass' => $password)));
$res = json_decode($res->getBody(), true);
if ($res['status'] > 0) {
if (User::where('email', $email)->exists()) {
$user = User::where('email', $email)->first();
Session::put('user_id', $user->PID);
return redirect('home');
}
$res = $client->post('https://api.pragyan.org/user/getDetails', array('body' => array('user_email' => $email, 'user_pass' => $password)));
$res = json_decode($res->getBody(), true);
if ($res['status'] == 2) {
$user = new User();
$user->name = $res['data']['user_fullname'];
$user->prag_pid = $res['data']['user_id'];
$user->email = $email;
$user->save();
$user = User::where('email', $email)->first();
Session::put('user_id', $user->PID);
return redirect('home');
} else {
return view('login', ['error' => 'Try after sometime']);
}
} else {
return view('login', ['error' => 'Email or password incorrect! If not registered, register at <a href="http://prgy.in/mdecoder">prgy.in/mdecoder</a>']);
}
}
示例2: registerWebPayModule
public function registerWebPayModule($payment = 'capture')
{
$I = $this;
$I->login();
$I->amOnPage('/admin/load_module_config.php?module_id=' . MDL_WEBPAY_ID);
$I->fillField('secret_key', WEBPAY_SECRET_KEY);
$I->fillField('publishable_key', WEBPAY_PUBLISHABLE_KEY);
$I->selectOption('input[name=payment]', $payment);
$I->click('この内容で登録する');
$I->amOnPage('/admin/ownersstore/');
$uri = 'http://localhost:9999/admin/ownersstore/';
$transactionId = $I->grabAttributeFrom('input[name=transactionid]', 'value');
$sessionId = $I->grabCookie('ECSESSID');
// posting file and handling confirm window are impossible for ghostdriver
$client = new Client();
$I->expectTo('install plugin');
$client->post($uri, ['body' => ['transactionid' => $transactionId, 'mode' => 'install', 'plugin_file' => fopen('WebPayExt.tar.gz', 'r')], 'cookies' => ['ECSESSID' => $sessionId]]);
$client->post($uri, ['body' => ['transactionid' => $transactionId, 'mode' => 'enable', 'plugin_id' => 1, 'enable' => 1], 'cookies' => ['ECSESSID' => $sessionId]]);
$I->amOnPage('/admin/ownersstore/');
$I->see('WebPay決済モジュール拡張プラグイン');
$I->seeCheckboxIsChecked('input#plugin_enable');
$I->seeInDatabase('dtb_payment', array('payment_id' => 5, 'memo03' => MDL_WEBPAY_CODE));
$I->haveInDatabase('dtb_payment_options', array('deliv_id' => 1, 'payment_id' => 5, 'rank' => 5));
$I->haveInDatabase('dtb_payment_options', array('deliv_id' => 2, 'payment_id' => 5, 'rank' => 2));
}
示例3: send
/**
* Send http request to api and return response.
*
* @param string $operation the operation type to perform
* @param array $args
*
* @return Response
*/
public function send($operation_type, array $args)
{
$fields = array_merge($this->authParams(), $args, compact('operation_type'));
$response = new Response($this->client->post($this->apiUrl, ['body' => Xml::arrayToXml($fields)]));
$response->offsetSet('original_args', $args);
return $response;
}
示例4: makeHttpRequest
/**
* Make a Http Request
* @param string $method The Http verb
* @param string $url The relative URL after the host name
* @param array|null $apiRequest Contents of the body
* @param array|null $queryString Data to add as a queryString to the url
* @return mixed
* @throws RequiredFieldMissingException
* @throws ConnectException
* @throws RequestException
* @throws \Exception
*/
public function makeHttpRequest($method, $url, $apiRequest = null, $queryString = null)
{
$this->apiConfiguration->validate();
$urlEndPoint = $this->apiConfiguration->getApiEndPoint() . '/' . $url;
$data = ['headers' => ['Authorization' => 'Bearer ' . $this->apiConfiguration->getAccessToken()], 'json' => $apiRequest, 'query' => $queryString];
try {
switch ($method) {
case 'post':
$response = $this->guzzle->post($urlEndPoint, $data);
break;
case 'put':
$response = $this->guzzle->put($urlEndPoint, $data);
break;
case 'delete':
$response = $this->guzzle->delete($urlEndPoint, $data);
break;
case 'get':
$response = $this->guzzle->get($urlEndPoint, $data);
break;
default:
throw new \Exception('Missing request method');
}
if (in_array(current($response->getHeader('Content-Type')), ['image/png', 'image/jpg'])) {
$result = $response->getBody()->getContents();
} else {
$result = json_decode($response->getBody(), true);
}
return $result;
} catch (ConnectException $c) {
throw $c;
} catch (RequestException $e) {
throw $e;
}
}
示例5: retrieveByCredentials
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
*
* @return \Magister\Services\Database\Elegant\Model|null
*/
public function retrieveByCredentials(array $credentials)
{
$body = ['body' => $credentials];
$this->client->delete('sessies/huidige');
$this->client->post('sessies', $body);
return $this->retrieveByToken();
}
示例6: createTeamMembership
public function createTeamMembership($teamId = '', $options = array())
{
if (sizeOf($options) < 1 || $teamId == '') {
return ApiException::errorMessage(999);
}
$requestParams = array();
$requestParams["teamId"] = $teamId;
if (isset($options["personId"])) {
$requestParams["personId"] = $options["personId"];
}
if (isset($options["personEmail"])) {
$requestParams["personEmail"] = $options["personEmail"];
}
if (isset($options["isModerator"])) {
$requestParams["isModerator"] = $options["isModerator"];
}
$mJson = json_encode($requestParams);
$client = new Client();
try {
$response = $client->post(self::TEAMMEMBERSHIPURI, array('headers' => $this->getBaseHeaders(), 'body' => $mJson, 'verify' => false));
} catch (ClientException $e) {
$errorResponse = $e->getResponse();
$statusCode = $errorResponse->getStatusCode();
if ($statusCode == 401) {
$response = $client->post(self::TEAMMEMBERSHIPURI, array('headers' => $this->getRefreshHeaders(), 'body' => $mJson, 'verify' => false));
} else {
if ($statusCode != 200) {
return ApiException::errorMessage($statusCode);
}
}
}
return $response;
}
示例7: postMo
public function postMo(array $messageArr)
{
try {
$this->msgCounter++;
$words = explode(' ', $messageArr['text']);
$moParams = array_merge($this->config['mo'], $messageArr, array('message_id' => $this->msgCounter, 'keyword' => $words[0] . '@' . $messageArr['short_id']));
echo "Posting params from MO to client @" . $messageArr['url'] . ': ' . json_encode($moParams) . "\n";
$response = $this->httpClient->post($messageArr['url'], ['body' => $moParams]);
if ($response->getStatusCode() != 200) {
echo 'received MO reply with status code: ' . $response->getStatusCode() . ', and body' . $response->getBody() . "\n";
return $this->sendError($response->getBody());
}
$responseBody = $response->getBody();
echo 'received MO reply:' . $responseBody . "\n";
$this->broadcast('mo_reply', array('message' => $this->parseXMLResponse($responseBody)));
} catch (\GuzzleHttp\Exception\RequestException $requestException) {
echo 'received MO reply error of class [' . get_class($requestException) . '] and message: ' . $requestException->getMessage() . "\n";
if ($requestException->hasResponse()) {
echo "\nbody: " . $requestException->getResponse()->getBody() . "\n";
echo "\ncode: " . $requestException->getResponse()->getStatusCode() . "\n";
$this->sendError($requestException->getMessage(), $this->parseXMLResponse($requestException->getResponse()->getBody()));
}
$this->sendError($requestException->getMessage());
} catch (\Exception $exc) {
echo 'received MO reply error of class [' . get_class($exc) . '] and message: ' . $exc->getMessage() . "\n";
$this->sendError($exc->getMessage());
}
}
示例8: request
/**
* Makes a request to a URL.
*
* @param string $request
* @param array $params
*
* @return \Psr7\Request
*/
protected function request($request, array $params = [])
{
$endpoint = $this->config->get('centurian.endpoint');
$uri = sprintf('%s/%s', $endpoint, $request);
$data = ['form_params' => $params, 'auth' => [$this->config->get('centurian.token'), null]];
return $this->client->post($uri, $data);
}
示例9: execute
/**
* Execute the command.
*
* @param InputInterface $input The input.
* @param OutputInterface $output The output.
* @throws InvalidArgumentException If the configuration is not specified.
* @return integer
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configFile = $input->getOption('config-file');
$config = Yaml::parse(file_get_contents($configFile), true);
if (!isset($config['strava']['auth'])) {
throw new InvalidArgumentException('There is no configuration specified for tracker "strava". See example config.');
}
$secretToken = $config['strava']['auth']['secretToken'];
$clientID = $config['strava']['auth']['clientID'];
$username = $config['strava']['auth']['username'];
$password = $config['strava']['auth']['password'];
$httpClient = new Client();
/** @var \GuzzleHttp\Message\ResponseInterface $response */
// Do normal login.
$response = $httpClient->get('https://www.strava.com/login', ['cookies' => true]);
$authenticityToken = $this->getAuthenticityToken($response);
// Perform the login to strava.com
$httpClient->post('https://www.strava.com/session', array('cookies' => true, 'body' => array('authenticity_token' => $authenticityToken, 'email' => $username, 'password' => $password)));
// Get the authorize page.
$response = $httpClient->get('https://www.strava.com/oauth/authorize?client_id=' . $clientID . '&response_type=code&redirect_uri=http://localhost&scope=view_private,write&approval_prompt=force', ['cookies' => true]);
$authenticityToken = $this->getAuthenticityToken($response);
// Accept the application.
$response = $httpClient->post('https://www.strava.com/oauth/accept_application?client_id=' . $clientID . '&response_type=code&redirect_uri=http://localhost&scope=view_private,write', array('cookies' => true, 'allow_redirects' => false, 'body' => array('authenticity_token' => $authenticityToken)));
$redirectLocation = $response->getHeader('Location');
$urlQuery = parse_url($redirectLocation, PHP_URL_QUERY);
parse_str($urlQuery, $urlQuery);
$authorizationCode = $urlQuery['code'];
// Token exchange.
$response = $httpClient->post('https://www.strava.com/oauth/token', array('body' => array('client_id' => $clientID, 'client_secret' => $secretToken, 'code' => $authorizationCode)));
$jsonResponse = $response->json();
$code = $jsonResponse['access_token'];
$output->writeln('Your access token is: <comment>' . $code . '</comment>');
return 0;
}
示例10: post
public function post($resource, $body, $type, $options = [])
{
$options['body'] = $this->serializer->serialize($body, 'json');
$options['headers'] = ['Content-Type' => 'application/json'];
$content = $this->client->post($resource, $options)->getBody()->getContents();
return $this->deserialize($content, $type);
}
示例11: post
public function post($full_url, array $multi_parts = [], array $headers = [])
{
$options = ['debug' => GUZZLE_DEBUG];
// Grab the client's handler instance.
$clientHandler = $this->client->getConfig('handler');
// Create a middleware that echoes parts of the request.
$tapMiddleware = Middleware::tap(function ($request) {
echo $request->getHeader('Content-Type');
// application/json
echo $request->getBody();
// {"foo":"bar"}
});
//$options['handler'] = $tapMiddleware($clientHandler);
$multi_part_vars = array();
foreach ($multi_parts as $name => $data) {
if (is_array($data)) {
$data['name'] = $name;
} else {
$data = ['name' => $name, 'contents' => $data];
}
$multi_part_vars[] = $data;
}
$options['multipart'] = $multi_part_vars;
//$options['headers'] = ['Referer' => $full_url];
if (!empty($headers)) {
$options['headers'] = $headers;
}
$this->response = $this->client->post($full_url, $options);
return $this;
}
示例12: validate
/**
* {@inheritdoc}
*/
public function validate($uri, $secret, $response, $remoteIp = NULL)
{
$params = ['secret' => $secret, 'response' => $response];
if ($remoteIp !== NULL) {
$params['remoteip'] = $remoteIp;
}
return $this->client->post($uri, ['query' => $params]);
}
示例13: send
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Psr\Http\Message\ResponseInterface
*/
public function send($notifiable, Notification $notification)
{
if (!($url = $notifiable->routeNotificationFor('slack'))) {
return;
}
$message = $notification->toSlack($notifiable);
return $this->http->post($url, ['json' => ['text' => $message->content, 'attachments' => $this->attachments($message)]]);
}
示例14: testGetAccessToken
public function testGetAccessToken()
{
$response = self::$client->post('/');
$token = $response->json();
$this->assertEquals("v6574b42-a5bc-4574-a87f-5c9d1202e316", $token['access_token']);
$this->assertEquals("308874923", $token['expires_in']);
$this->assertEquals("Bearer", $token['token_type']);
}
示例15: publish
/**
* {@inheritdoc}
*/
public function publish(Event $event)
{
try {
$this->client->post(self::PUBLISH_URL, ['body' => $this->serializer->serialize($event, 'json')]);
} catch (BadResponseException $exception) {
throw new PublishException($exception->getMessage());
}
}