gpt4 book ai didi

php - Httpful 发布表单数据

转载 作者:可可西里 更新时间:2023-11-01 13:53:56 26 4
gpt4 key购买 nike

我正在使用来自 http://phphttpclient.com/ 的 Httpful PHP 库,这是我的示例代码:

$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();

我的问题是如何添加表单数据。我试图阅读文档,但找不到任何解释,只有发送 xml 和 Json 示例,但我无法在请求中获得带有表单数据的正常 POST。

有人请帮助我..

最佳答案

终于我找到了答案,感谢@Xiquid 指导我找到答案,这是我使用 php httpful rest 客户端发送帖子数据的工作答案:

$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();

关于php - Httpful 发布表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27596663/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com