Httpful пост формы данных

Я использую Httpful PHP библиотеку из http://phphttpclient.com/ , вот мой пример кода:

$data =  array(
'code'          => $request->query->get('code'),
'client_id'     => $this->container->getParameter('GOOGLE_CLIENT_ID'),
'client_secret' => $this->container->getParameter('GOOGLE_CLIENT_SECRET'),
'redirect_uri'  => $google_redirect,
'grant_type'    => "authorization_code");

$response = Request::post($url)->body($data)->sendsType(Mime::FORM)->send();

var_dump($response);
die();

мой вопрос, как добавить данные формы.
Я пытался прочитать документацию, но не смог найти объяснения, есть только пример send xml и Json, но я не могу получить нормальный POST с данными формы внутри запроса.

кто-нибудь, пожалуйста, помогите мне ..

5

Решение

наконец, я нашел ответ, благодаря @Xiquid, который помогает мне найти ответ, вот мой рабочий ответ для отправки данных поста с помощью php httpful rest client:

$google_redirect = $request->getSchemeAndHttpHost().$this->generateUrl('myroutename')."?platform=google";
$url =  "https://www.googleapis.com/oauth2/v3/token";

$data =  array(
'code'          => $request->query->get('code'),
'client_id'     => $this->container->getParameter('GOOGLE_CLIENT_ID'),
'client_secret' => $this->container->getParameter('GOOGLE_CLIENT_SECRET'),
'redirect_uri'  => $google_redirect,
'grant_type'    => "authorization_code");$response = RestRequester::post($url)
->method(Http::POST)        // Alternative to Request::post
->withoutStrictSsl()        // Ease up on some of the SSL checks
->expectsJson()             // Expect HTML responses
->sendsType(Mime::FORM)

->body('grant_type=authorization_code&code='.$data['code']."&client_id=".$data['client_id']."&client_secret=".$data['client_secret']."&redirect_uri=".$data['redirect_uri'])
->send();

var_dump($response);
die();
7

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector